Yum needs to know what software should be installed on your system. For instance, if you are using Fedora Core 2, then it needs to know what packages make up a standard install of Fedora Core 2. The packages needed for a particular Linux distribution are stored in repositories on the Internet. To properly configure yum, you need to open a file called /etc/yum.conf
, and make sure it contains the proper information. In other words, you use yum.conf to point yum at the repositories on the Internet that define the files needed for your distribution of Linux.
一个/etc/yum.conf文件实例
package in yum is an rpm file. Each rpm file has a header, that defines the contents of the file and any dependencies it might have. In particular, it defines the versions of the programs upon which the code in the rpm file depends.
用命令 rpm -qpl *.rpm
用命令 rpm2cpio *.rpm | cpio -div
yum list
When you first start yum by becoming root and typing yum list
, it usually spends a long time (15 to 60 minutes) downloading not entire rpm files, but instead the headers for all the rpm files that define your distribution.
yum update
After it has downloaded all these headers, then you can issue a command like yum update
, and yum will compare the current contents of your system to the records found in the rpm headers it has downloaded. If some of the headers reference files that are more recent than the files currently installed on your system, then yum will automatically download the needed complete rpm files and use them to update your system.
yum info <name>
查询某个软件
[root@centos repodata]# yum info glibc
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: centos.ustc.edu.cn
* updates: mirrors.pubyun.com
Installed Packages
Name : glibc
Arch : x86_64
Version : 2.12
Release : 1.149.el6
Size : 12 M
Repo : installed
From repo : anaconda-CentOS-201410241409.x86_64
Summary : The GNU libc libraries
URL : http://sources.redhat.com/glibc/
License : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
Description : The glibc package contains standard libraries which are used by
: multiple programs on the system. In order to save disk space and
: memory, as well as to make upgrading easier, common system code is
: kept in one place and shared between programs. This particular package
: contains the most important sets of shared libraries: the standard C
: library and the standard math library. Without these two libraries, a
: Linux system will not function. Available Packages Name : glibc
Arch : i686
Version : 2.12
Release : 1.149.el6_6.9
Size : 4.3 M
Repo : updates
Summary : The GNU libc libraries
URL : http://sources.redhat.com/glibc/
License : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
Description : The glibc package contains standard libraries which are used by
: multiple programs on the system. In order to save disk space and
: memory, as well as to make upgrading easier, common system code is
: kept in one place and shared between programs. This particular package
: contains the most important sets of shared libraries: the standard C
: library and the standard math library. Without these two libraries, a
: Linux system will not function. Name : glibc
Arch : x86_64
Version : 2.12
Release : 1.149.el6_6.9
Size : 3.8 M
Repo : updates
Summary : The GNU libc libraries
URL : http://sources.redhat.com/glibc/
License : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
Description : The glibc package contains standard libraries which are used by
: multiple programs on the system. In order to save disk space and
: memory, as well as to make upgrading easier, common system code is
: kept in one place and shared between programs. This particular package
: contains the most important sets of shared libraries: the standard C
: library and the standard math library. Without these two libraries, a
: Linux system will not function.
yum -q <package-name>
RPM’s Package Label
RPM’s package label is a string that uniquely identifies every installed package, and every label contains three pieces of information:
- The name of the packaged software.
- The version of the packaged software.
- The package’s release number.
在使用rpm -q <package-name>
查询时,package-name有以下限制:
- case-sentitive
- 不支持对package-name、version number、release number的部分匹配
- 不支持wildcard
yum -f
rpm -qp <package-file>
一个RPM的文件名与它所包含的软件的名字并没有关系。
通过命令rpm -qp
可以查看一个RPM文件中包含的软件的名字
Yum命令小结
Besides the headers for your distribution, you can configure yum to reference other repositories that contain additional files that might interest you. Once the headers are in place, you can download all or part of the packages found in these repositories.
We can install new software on Red Hat/CentOS Linux with yum install packagename
command from console. Running this command first checks for existing YUM Repository configuration files in /etc/yum.repos.d/
directory. It reads each YUM Repository configuration file to get the information required to download and install new software, resolves software dependencies and installs the required RPM package files.
- be located in
/etc/yum.repos.d/
directory- have
.repo
extension, to be recognized by YUM
Repository ID - One word unique repository ID (example: [examplerepo])
Baseurl - URL to the repodata directory. You can use
file://path
if repository is located locally orftp://link, http://link, https://link
if repository is located remotely - HTTP Authentication available http://user:password@www.repo1.com/repo1 (example: baseurl=http://mirror.cisp.com/CentOS/6/os/i386/)Gpgcheck - Enable/disable GPG signature checking (example: gpgcheck=1)
Exclude - List of the packages to exclude (example: exclude=httpd,mod_ssl)
Includepkgs - List of the packages to include (example: include=kernel)
- Repository ID
- Name
- Baseurl
- Enabled
先看一个例子:/etc/yum.repos.d/CentOS-Base.repo中的一个容器
其中,
[base]
- 是这个容器的名称,中括号必须有,内容无所谓,但是不能有重复的名字
name
- 类似于注释,没什么实际意义
mirrorlist
- 映射站点
#baseurl
- 容器的实际网址,这个最重要
gpgcheck
- 是否需要核对RPM的数字签名
enable
- 是否使用这个容器,为『1』是启用,为『0』是不启用
gpgkey
- 数字签名的公钥所在的位置
Yum 的缓存文件的位置一般在 /var/cache/yum
,这个设置可以从/etc/yum.conf
中的cachedir
看出。
Taking the Red Hat Package Manager to the Limit