Rpm
在 Linux 操作系统下,几乎所有的软件均通过RPM 进行安装、卸载及管理等操作。RPM 的全称为Redhat Package Manager ,是由Redhat 公司提出的,用于管理Linux 下软件包的软件。Linux 安装时,除了几个核心模块以外,其余几乎所有的模块均通过RPM 完成安装。RPM 有五种操作模式,分别为:安装、卸载、升级、查询和验证。
1)用RPM安装软件包,最简单的命令如下:
1 #rpm -i example.rpm 安装 example.rpm 包;
2 #rpm -iv example.rpm 安装 example.rpm 包并在安装过程中显示正在安装的文件信息;
3 #rpm -ivh example.rpm 安装 example.rpm 包并在安装过程中显示正在安装的文件信息及安装进度
2)删除已安装的软件包
要卸载软件包example,只需输入以下这行命令:
1 # rpm -e example
注意:软件包名是example,而不是rpm文件名"example.rpm"。
3)升级软件包
升级软件类似于安装软件:
1 # rpm -Uvh example.rpm
用户要注意的是:rpm会自动卸载相应软件包的老版本。如果老版本软件的配置文件通新版本的不兼容,rpm会自动将其保存为另外一个文件,用户会看到下面的信息:
saving /etc/example.conf as /etc/example.conf.rpmsave
这样用户就可以自己手工去更改相应的配置文件。
另外如果用户要安装老版本的软件,用户就会看到下面的出错信息:
# rpm -Uvh example.rpm
examle packag example-2.0-l(which is newer) is already installed
error:example.rpm cannot be installed
如果用户要强行安装就使用-oldpackage参数。
4)查询软件包
用户可以用rpm -q在rpm的数据库中查询相应的软件,rpm会给出软件包的名称,版本,发布版本号,例如:
1 # rpm -q example
下面是查询时可以使用的特定参数:
-a :查询目前系统安装的所有软件包。
-f 文件名 :查询包括该文件的软件包。
-F :同-f参数,只是输入是标准输入(例如 find /usr/bin | rpm -qF)
-q 软件包名 : 查询该软件包
-Q :同-p参数,只是输入是标准输入(例如 find /mnt/cdrom/RedHat/RPMS | rpm -qQ)
下面是输出时的格式选择:
-i 显示软件包的名称,描述,发行,大小,编译日期,安装日期,开发人员等信息。
-l 显示软件包包含的文件
-s 显示软件包包含的文件目前的状态,只有两种状态:normal和missing
-d 显示软件包中的文档(如man,info,README等)
-c 显示软件包中的配置文件,这些文件一般是安装后需要用户手工修改的,例如:sendmail.cf,passwd,inittab等
如果用-v参数就可以得到类似于ls -l的输出
5)用rpm校验软件包
1 rpm -Vf 需要验证到包
yum
https://access.redhat.com/articles/yum-cheat-sheet
Working with Packages
Yum enables you to perform a complete set of operations with software packages, including searching for packages, viewing information about them, installing and removing.
9.2.1. Searching Packages
You can search all RPM package names, descriptions and summaries by using the following command:
yum search term…
Replace term with a package name you want to search.
Example 9.4. Searching for packages matching a specific string
To list all packages that match "vim", "gvim", or "emacs", type:
~]$ yum search vim gvim emacs
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
============================= N/S matched: vim ==============================
vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
[output truncated]
============================ N/S matched: emacs =============================
emacs.x86_64 : GNU Emacs text editor
emacs-auctex.noarch : Enhanced TeX modes for Emacs
[output truncated]
Name and summary matches mostly, use "search all" for everything.
Warning: No matches found for: gvim
The yum search
command is useful for searching for packages you do not know the name of, but for which you know a related term. Note that by default, yum search
returns matches in package name and summary, which makes the search faster. Use the yum search all
command for a more exhaustive but slower search.
Filtering the Results
All of yum’s list commands allow you to filter the results by appending one or more glob expressions as arguments. Glob expressions are normal strings of characters which contain one or more of the wildcard characters *
(which expands to match any character subset) and ?
(which expands to match any single character).
Be careful to escape the glob expressions when passing them as arguments to a yum
command, otherwise the Bash shell will interpret these expressions as pathname expansions, and potentially pass all files in the current directory that match the global expressions to yum
. To make sure the glob expressions are passed to yum
as intended, use one of the following methods:
- escape the wildcard characters by preceding them with a backslash character
- double-quote or single-quote the entire glob expression.
Examples in the following section demonstrate usage of both these methods.
9.2.2. Listing Packages
To list information on all installed and available packages type the following at a shell prompt:
yum list all
To list installed and available packages that match inserted glob expressions use the following command:
yum list glob_expression…
Example 9.5. Listing ABRT-related packages
Packages with various ABRT add-ons and plug-ins either begin with "abrt-addon-", or "abrt-plugin-". To list these packages, type the following command at a shell prompt. Note how the wildcard characters are escaped with a backslash character:
~]$ yum list abrt-addon\* abrt-plugin\*
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
Installed Packages
abrt-addon-ccpp.x86_64 2.1.11-35.el7 @rhel-7-server-rpms
abrt-addon-kerneloops.x86_64 2.1.11-35.el7 @rhel-7-server-rpms
abrt-addon-pstoreoops.x86_64 2.1.11-35.el7 @rhel-7-server-rpms
abrt-addon-python.x86_64 2.1.11-35.el7 @rhel-7-server-rpms
abrt-addon-vmcore.x86_64 2.1.11-35.el7 @rhel-7-server-rpms
abrt-addon-xorg.x86_64 2.1.11-35.el7 @rhel-7-server-rpms
To list all packages installed on your system use the installed
keyword. The rightmost column in the output lists the repository from which the package was retrieved.
yum list installed glob_expression…
Example 9.6. Listing all installed versions of the krb package
The following example shows how to list all installed packages that begin with "krb" followed by exactly one character and a hyphen. This is useful when you want to list all versions of certain component as these are distinguished by numbers. The entire glob expression is quoted to ensure proper processing.
~]$ yum list installed "krb?-*"
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
Installed Packages
krb5-libs.x86_64 1.13.2-10.el7 @rhel-7-server-rpms
To list all packages in all enabled repositories that are available to install, use the command in the following form:
yum list available glob_expression…
Example 9.7. Listing available gstreamer plug-ins
For instance, to list all available packages with names that contain "gstreamer" and then "plugin", run the following command:
~]$ yum list available gstreamer*plugin\*
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
Available Packages
gstreamer-plugins-bad-free.i686 0.10.23-20.el7 rhel-7-server-rpms
gstreamer-plugins-base.i686 0.10.36-10.el7 rhel-7-server-rpms
gstreamer-plugins-good.i686 0.10.31-11.el7 rhel-7-server-rpms
gstreamer1-plugins-bad-free.i686 1.4.5-3.el7 rhel-7-server-rpms
gstreamer1-plugins-base.i686 1.4.5-2.el7 rhel-7-server-rpms
gstreamer1-plugins-base-devel.i686 1.4.5-2.el7 rhel-7-server-rpms
gstreamer1-plugins-base-devel.x86_64 1.4.5-2.el7 rhel-7-server-rpms
gstreamer1-plugins-good.i686 1.4.5-2.el7 rhel-7-server-rpms
Listing Repositories
To list the repository ID, name, and number of packages for each enabled repository on your system, use the following command:
yum repolist
To list more information about these repositories, add the -v
option. With this option enabled, information including the file name, overall size, date of the last update, and base URL are displayed for each listed repository. As an alternative, you can use the repoinfo
command that produces the same output.
yum repolist -v
yum repoinfo
To list both enabled and disabled repositories use the following command. A status column is added to the output list to show which of the repositories are enabled.
yum repolist all
By passing disabled
as a first argument, you can reduce the command output to disabled repositories. For further specification you can pass the ID or name of repositories or related glob_expressions as arguments. Note that if there is an exact match between the repository ID or name and the inserted argument, this repository is listed even if it does not pass the enabled or disabled filter.
9.2.3. Displaying Package Information
To display information about one or more packages, use the following command (glob expressions are valid here as well):
yum info package_name…
Replace package_name with the name of the package.
Example 9.8. Displaying information on the abrt package
To display information about the abrt package, type:
~]$ yum info abrt
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
Installed Packages
Name : abrt
Arch : x86_64
Version : 2.1.11
Release : 35.el7
Size : 2.3 M
Repo : installed
From repo : rhel-7-server-rpms
Summary : Automatic bug detection and reporting tool
URL : https://fedorahosted.org/abrt/
License : GPLv2+
Description : abrt is a tool to help users to detect defects in applications and
: to create a bug report with all information needed by maintainer to fix
: it. It uses plugin system to extend its functionality.
The yum info *package_name*
command is similar to the rpm -q --info *package_name*
command, but provides as additional information the name of the yum repository the RPM package was installed from (look for the From repo:
line in the output).
Using yumdb
You can also query the yum database for alternative and useful information about a package by using the following command:
yumdb info package_name
This command provides additional information about a package, including the check sum of the package (and the algorithm used to produce it, such as SHA-256), the command given on the command line that was invoked to install the package (if any), and the reason why the package is installed on the system (where user
indicates it was installed by the user, and dep
means it was brought in as a dependency).
Example 9.9. Querying yumdb for information on the yum package
To display additional information about the yum package, type:
~]$ yumdb info yum
Loaded plugins: langpacks, product-id
yum-3.4.3-132.el7.noarch
changed_by = 1000
checksum_data = a9d0510e2ff0d04d04476c693c0313a11379053928efd29561f9a837b3d9eb02
checksum_type = sha256
command_line = upgrade
from_repo = rhel-7-server-rpms
from_repo_revision = 1449144806
from_repo_timestamp = 1449144805
installed_by = 4294967295
origin_url = https://cdn.redhat.com/content/dist/rhel/server/7/7Server/x86_64/os/Packages/yum-3.4.3-132.el7.noarch.rpm
reason = user
releasever = 7Server
var_uuid = 147a7d49-b60a-429f-8d8f-3edb6ce6f4a1
For more information on the yumdb
command, see the yumdb(8) manual page.
9.2.4. Installing Packages
To install a single package and all of its non-installed dependencies, enter a command in the following form as root
:
yum install package_name
安装指定的版本
yum默认都是安装最新版的软件,这样可能会出一些问题,或者我们希望yum安装指定(特定)版本(旧版本)软件包.所以,就顺带分享yum安装指定(特定)版本(旧版本)软件包的方法。
过程如下: 假设这里是我们想安装的是prce ,输入:
#yum list prce
输出:
pcre-7.8-6.el6.i686:Perl-compatibleregularexpressionlibrary
pcre-7.8-6.el6.x86_64:Perl-compatibleregularexpressionlibrary
pcre-7.8-6.el6.x86_64:Perl-compatibleregularexpressionlibrary
找到你要安装的版本的完整的名字,这里安装pcre-7.8-6.el6.i686,输入:
#yum install pcre-7.8-6.el6.i686 -y
安装完后,就是检查pcre的版本了,输入:
# rpm -qa | grep pcre
就可以看到你安装的版本是不是你要的了。
You can also install multiple packages simultaneously by appending their names as arguments. To do so, type as root
:
yum install package_name package_name…
If you are installing packages on a multilib system, such as an AMD64 or Intel 64 machine, you can specify the architecture of the package (as long as it is available in an enabled repository) by appending .arch to the package name:
yum install package_name.arch
Example 9.10. Installing packages on multilib system
To install the sqlite package for the i686
architecture, type:
~]# yum install sqlite.i686
You can use glob expressions to quickly install multiple similarly named packages. Execute as root
:
yum install glob_expression…
Example 9.11. Installing all audacious plugins
Global expressions are useful when you want to install several packages with similar names. To install all audacious plug-ins, use the command in the following form:
~]# yum install audacious-plugins-\*
In addition to package names and glob expressions, you can also provide file names to yum install
. If you know the name of the binary you want to install, but not its package name, you can give yum install
the path name. As root
, type:
yum install /usr/sbin/named
Yum then searches through its package lists, finds the package which provides /usr/sbin/named
, if any, and prompts you as to whether you want to install it.
As you can see in the above examples, the yum install
command does not require strictly defined arguments. It can process various formats of package names and glob expressions, which makes installation easier for users. On the other hand, it takes some time until yum parses the input correctly, especially if you specify a large number of packages. To optimize the package search, you can use the following commands to explicitly define how to parse the arguments:
yum install-n name
yum install-na name.architecture
yum install-nevra name-epoch:version-release.architecture
With install-n
, yum interprets name as the exact name of the package. The install-na
command tells yum that the subsequent argument contains the package name and architecture divided by the dot character. With install-nevra
, yum will expect an argument in the form name-epoch:version-release.architecture. Similarly, you can use yum remove-n
, yum remove-na
, and yum remove-nevra
when searching for packages to be removed.
Note
If you know you want to install the package that contains the named
binary, but you do not know in which bin/
or sbin/
directory the file is installed, use the yum provides
command with a glob expression:
~]# yum provides "*bin/named"
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
32:bind-9.9.4-14.el7.x86_64 : The Berkeley Internet Name Domain (BIND) DNS
: (Domain Name System) server
Repo : rhel-7-server-rpms
Matched from:
Filename : /usr/sbin/named
yum provides "*/*file_name*"
is a useful way to find the packages that contain file_name.
Example 9.12. Installation Process
The following example provides an overview of installation with use of yum. To download and install the latest version of the httpd package, execute as root
:
~]# yum install httpd
Loaded plugins: langpacks, product-id, subscription-manager
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-12.el7 will be updated
---> Package httpd.x86_64 0:2.4.6-13.el7 will be an update
--> Processing Dependency: 2.4.6-13.el7 for package: httpd-2.4.6-13.el7.x86_64
--> Running transaction check
---> Package httpd-tools.x86_64 0:2.4.6-12.el7 will be updated
---> Package httpd-tools.x86_64 0:2.4.6-13.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
After executing the above command, yum loads the necessary plug-ins and runs the transaction check. In this case, httpd is already installed. Since the installed package is older than the latest currently available version, it will be updated. The same applies to the httpd-tools package that httpd depends on. Then, a transaction summary is displayed:
================================================================================
Package Arch Version Repository Size
================================================================================
Updating:
httpd x86_64 2.4.6-13.el7 rhel-x86_64-server-7 1.2 M
Updating for dependencies:
httpd-tools x86_64 2.4.6-13.el7 rhel-x86_64-server-7 77 k
Transaction Summary
================================================================================
Upgrade 1 Package (+1 Dependent package)
Total size: 1.2 M
Is this ok [y/d/N]:
In this step yum prompts you to confirm the installation. Apart from y
(yes) and N
(no) options, you can choose d
(download only) to download the packages but not to install them directly. If you choose y
, the installation proceeds with the following messages until it is finished successfully.
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : httpd-tools-2.4.6-13.el7.x86_64 1/4
Updating : httpd-2.4.6-13.el7.x86_64 2/4
Cleanup : httpd-2.4.6-12.el7.x86_64 3/4
Cleanup : httpd-tools-2.4.6-12.el7.x86_64 4/4
Verifying : httpd-2.4.6-13.el7.x86_64 1/4
Verifying : httpd-tools-2.4.6-13.el7.x86_64 2/4
Verifying : httpd-tools-2.4.6-12.el7.x86_64 3/4
Verifying : httpd-2.4.6-12.el7.x86_64 4/4
Updated:
httpd.x86_64 0:2.4.6-13.el7
Dependency Updated:
httpd-tools.x86_64 0:2.4.6-13.el7
Complete!
To install a previously downloaded package from the local directory on your system, use the following command:
yum localinstall path
Replace path with the path to the package you want to install.
9.2.5. Downloading Packages
As shown in Example 9.12, “Installation Process”, at a certain point of installation process you are prompted to confirm the installation with the following message:
...
Total size: 1.2 M
Is this ok [y/d/N]:
...
With the d
option, yum downloads the packages without installing them immediately. You can install these packages later offline with the yum localinstall
command or you can share them with a different device. Downloaded packages are saved in one of the subdirectories of the cache directory, by default /var/cache/yum/$basearch/$releasever/packages/
. The downloading proceeds in background mode so that you can use yum for other operations in parallel.
9.2.6. Removing Packages
Similarly to package installation, yum enables you to uninstall them. To uninstall a particular package, as well as any packages that depend on it, run the following command as root
:
yum remove package_name…
As when you install multiple packages, you can remove several at once by adding more package names to the command.
Example 9.13. Removing several packages
To remove totem, type the following at a shell prompt:
~]# yum remove totem
Similar to install
, remove
can take these arguments:
- package names
- glob expressions
- file lists
- package provides
Warning
Yum is not able to remove a package without also removing packages which depend on it. This type of operation, which can only be performed by RPM, is not advised, and can potentially leave your system in a non-functioning state or cause applications to not work correctly or crash.
yum repo
Setting [repository] Options
The [*repository*]
sections, where repository is a unique repository ID such as my_personal_repo
(spaces are not permitted), allow you to define individual Yum repositories. To avoid conflicts, custom repositories should not use names used by Red Hat repositories.
The following is a bare-minimum example of the form a [*repository*]
section takes:
[repository]
name=repository_name
baseurl=repository_url
Every [*repository*]
section must contain the following directives:
-
name
=repository_namewhere repository_name is a human-readable string describing the repository.
-
baseurl
=repository_urlwhere repository_url is a URL to the directory where the
repodata
directory of a repository is located:If the repository is available over HTTP, use:http://path/to/repo
If the repository is available over FTP, use:ftp://path/to/repo
If the repository is local to the machine, use:file:///path/to/local/repo
If a specific online repository requires basic HTTP authentication, you can specify your user name and password by prepending it to the URL as*username*:*password*@*link*
. For example, if a repository on http://www.example.com/repo/ requires a user name of “user” and a password of “password”, then thebaseurl
link could be specified ashttp://**
user**:**
password**@www.example.com/repo/
.Usually this URL is an HTTP link, such as:baseurl=http://path/to/repo/releases/$releasever/server/$basearch/os/
Note that Yum always expands the$releasever
,$arch
, and$basearch
variables in URLs. For more information about Yum variables, see Section 8.4.3, “Using Yum Variables”.
Another useful [*repository*]
directive is the following:
-
enabled
=valuewhere value is one of:
0
— Do not include this repository as a package source when performing updates and installs. This is an easy way of quickly turning repositories on and off, which is useful when you desire a single package from a repository that you do not want to enable for updates or installs.1
— Include this repository as a package source.Turning repositories on and off can also be performed by passing either the--enablerepo=*repo_name*
or--disablerepo=*repo_name*
option toyum
, or through the Add/Remove Software window of the PackageKit utility.
Many more [*repository*]
options exist. For a complete list, see the [repository] OPTIONS
section of the yum.conf(5) manual page.
Example 8.6. A sample /etc/yum.repos.d/redhat.repo file
The following is a sample /etc/yum.repos.d/redhat.repo
file:
Expand
#
# Red Hat Repositories
# Managed by (rhsm) subscription-manager
#
[red-hat-enterprise-linux-scalable-file-system-for-rhel-6-entitlement-rpms]
name = Red Hat Enterprise Linux Scalable File System (for RHEL 6 Entitlement) (RPMs)
baseurl = https://cdn.redhat.com/content/dist/rhel/entitlement-6/releases/$releasever/$basearch/scalablefilesystem/os
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslcacert = /etc/rhsm/ca/redhat-uep.pem
sslclientkey = /etc/pki/entitlement/key.pem
sslclientcert = /etc/pki/entitlement/11300387955690106.pem
[red-hat-enterprise-linux-scalable-file-system-for-rhel-6-entitlement-source-rpms]
name = Red Hat Enterprise Linux Scalable File System (for RHEL 6 Entitlement) (Source RPMs)
baseurl = https://cdn.redhat.com/content/dist/rhel/entitlement-6/releases/$releasever/$basearch/scalablefilesystem/source/SRPMS
enabled = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslcacert = /etc/rhsm/ca/redhat-uep.pem
sslclientkey = /etc/pki/entitlement/key.pem
sslclientcert = /etc/pki/entitlement/11300387955690106.pem
[red-hat-enterprise-linux-scalable-file-system-for-rhel-6-entitlement-debug-rpms]
name = Red Hat Enterprise Linux Scalable File System (for RHEL 6 Entitlement) (Debug RPMs)
baseurl = https://cdn.redhat.com/content/dist/rhel/entitlement-6/releases/$releasever/$basearch/scalablefilesystem/debug
enabled = 0
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
sslverify = 1
sslcacert = /etc/rhsm/ca/redhat-uep.pem
sslclientkey = /etc/pki/entitlement/key.pem
sslclientcert = /etc/pki/entitlement/11300387955690106.pem
Using Yum Variables
You can use and reference the following built-in variables in yum
commands and in all Yum configuration files (that is, /etc/yum.conf
and all .repo
files in the /etc/yum.repos.d/
directory):
-
$releasever
You can use this variable to reference the release version of Red Hat Enterprise Linux. Yum obtains the value of
$releasever
from thedistroverpkg=*value*
line in the/etc/yum.conf
configuration file. If there is no such line in/etc/yum.conf
, thenyum
infers the correct value by deriving the version number from the redhat-release-server package. The value of$releasever
typically consists of the major release number and the variant of Red Hat Enterprise Linux, for example6Client
, or6Server
. -
$arch
You can use this variable to refer to the system's CPU architecture as returned when calling Python's
os.uname()
function. Valid values for$arch
includei686
andx86_64
. -
$basearch
You can use
$basearch
to reference the base architecture of the system. For example, i686 machines have a base architecture ofi386
, and AMD64 and Intel 64 machines have a base architecture ofx86_64
. -
$YUM0-9
These ten variables are each replaced with the value of any shell environment variables with the same name. If one of these variables is referenced (in
/etc/yum.conf
for example) and a shell environment variable with the same name does not exist, then the configuration file variable is not replaced.
To define a custom variable or to override the value of an existing one, create a file with the same name as the variable (without the “$
” sign) in the /etc/yum/vars/
directory, and add the desired value on its first line.
For example, repository descriptions often include the operating system name. To define a new variable called $osname
, create a new file with “Red Hat Enterprise Linux” on the first line and save it as /etc/yum/vars/osname
:
~]# echo "Red Hat Enterprise Linux" > /etc/yum/vars/osname
Instead of “Red Hat Enterprise Linux 6”, you can now use the following in the .repo
files:
name=$osname $releasever
Viewing the Current Configuration
To display the current values of global Yum options (that is, the options specified in the [main]
section of the /etc/yum.conf
file), run the yum-config-manager
with no command-line options:
yum-config-manager
To list the content of a different configuration section or sections, use the command in the following form:
yum-config-manager section
You can also use a glob expression to display the configuration of all matching sections:
yum-config-manager glob_expression
For example, to list all configuration options and their corresponding values, type the following at a shell prompt:
~]$ yum-config-manager main \*
Loaded plugins: product-id, refresh-packagekit, subscription-manager
================================== main ===================================
[main]
alwaysprompt = True
assumeyes = False
bandwith = 0
bugtracker_url = https://bugzilla.redhat.com/enter_bug.cgi?product=Red%20Hat%20Enterprise%20Linux%206&component=yum
cache = 0
[output truncated]
实际使用如下:
yum-config-manager rabbitmq_rabbitmq-server-source
Loaded plugins: fastestmirror
======================================================================================== repo: rabbitmq_rabbitmq-server-source ========================================================================================
[rabbitmq_rabbitmq-server-source]
....
list available repository ID
yum repolist all
Adding, Enabling, and Disabling a Yum Repository
[Section 8.4.2, “Setting repository] Options” described various options you can use to define a Yum repository. This section explains how to add, enable, and disable a repository by using the yum-config-manager
command.
Important
When the system is registered with the certificate-based Red Hat Network
, the Red Hat Subscription Manager tools are used to manage repositories in the /etc/yum.repos.d/redhat.repo
file. See Chapter 6, Registering the System and Managing Subscriptions for more information how to register a system with Red Hat Network
and use the Red Hat Subscription Manager tools to manage subscriptions.
Adding a Yum Repository
To define a new repository, you can either add a [*repository*]
section to the /etc/yum.conf
file, or to a .repo
file in the /etc/yum.repos.d/
directory. All files with the .repo
file extension in this directory are read by yum
, and it is recommended to define your repositories here instead of in /etc/yum.conf
.
Warning
Obtaining and installing software packages from unverified or untrusted software sources other than Red Hat Network constitutes a potential security risk, and could lead to security, stability, compatibility, and maintainability issues.
Yum repositories commonly provide their own .repo
file. To add such a repository to your system and enable it, run the following command as root
:
yum-config-manager --add-repo repository_url
where repository_url is a link to the .repo
file. For example, to add a repository located at http://www.example.com/example.repo, type the following at a shell prompt:
~]# yum-config-manager --add-repo http://www.example.com/example.repo
Loaded plugins: product-id, refresh-packagekit, subscription-manager
adding repo from: http://www.example.com/example.repo
grabbing file http://www.example.com/example.repo to /etc/yum.repos.d/example.repo
example.repo | 413 B 00:00
repo saved to /etc/yum.repos.d/example.repo
Enabling a Yum Repository
To enable a particular repository or repositories, type the following at a shell prompt as root
:
yum-config-manager --enable repository
where repository is the unique repository ID (use yum repolist all
to list available repository IDs). Alternatively, you can use a glob expression to enable all matching repositories:
yum-config-manager --enable glob_expression
For example, to enable repositories defined in the [example]
, [example-debuginfo]
, and [example-source]
sections, type:
~]# yum-config-manager --enable example\*
Loaded plugins: product-id, refresh-packagekit, subscription-manager
============================== repo: example ==============================
[example]
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/6Server
baseurl = http://www.example.com/repo/6Server/x86_64/
cache = 0
cachedir = /var/cache/yum/x86_64/6Server/example
[output truncated]
When successful, the yum-config-manager --enable
command displays the current repository configuration.
Disabling a Yum Repository
To disable a Yum repository, run the following command as root
:
yum-config-manager --disable repository
where repository is the unique repository ID (use yum repolist all
to list available repository IDs). Similarly to yum-config-manager --enable
, you can use a glob expression to disable all matching repositories at the same time:
yum-config-manager --disable glob_expression
When successful, the yum-config-manager --disable
command displays the current configuration.
Working with Yum Cache
By default, yum deletes downloaded data files when they are no longer needed after a successful operation. This minimizes the amount of storage space that yum uses. However, you can enable caching, so that the package files downloaded by yum stay in cache directories. By using cached data, you can carry out certain operations without a network connection, you can also copy packages stored in the caches and reuse them elsewhere.
Yum stores temporary files in the /var/cache/yum/$basearch/$releasever/
directory, where $basearch
and $releasever
are Yum variables referring to base architecture of the system and the release version of Red Hat Enterprise Linux. Each configured repository has one subdirectory. For example, the directory /var/cache/yum/$basearch/$releasever/development/packages/
holds packages downloaded from the development repository. You can find the values for the basearch* and *releasever variables in the output of the yum version
command.
To change the default cache location, modify the cachedir
option in the [main]
section of the /etc/yum.conf
configuration file. See Section 8.4, “Configuring Yum and Yum Repositories” for more information on configuring yum.
Enabling the Caches
To retain the cache of packages after a successful installation, add the following text to the [main]
section of /etc/yum.conf
.
keepcache = 1
Once you enabled caching, every yum operation may download package data from the configured repositories.
To download and make usable all the metadata for the currently enabled yum repositories, type:
yum makecache
This is useful if you want to make sure that the cache is fully up to date with all metadata. To set the time after which the metadata will expire, use the metadata-expire
setting in /etc/yum.conf
.
Using yum in Cache-only Mode
To carry out a yum command without a network connection, add the -C
or --cacheonly
command-line option. With this option, yum proceeds without checking any network repositories, and uses only cached files. In this mode, yum may only install packages that have been downloaded and cached by a previous operation.
For instance, to list packages that use the currently cached data with names that contain “gstreamer”, enter the following command:
yum -C list gstreamer*
Clearing the yum Caches
It is often useful to remove entries accumulated in the /var/cache/yum/
directory. If you remove a package from the cache, you do not affect the copy of the software installed on your system. To remove all entries for currently enabled repositories from the cache, type the following as a root
:
yum clean all
There are various ways to invoke yum
in clean
mode depending on the type of cached data you want to remove. See Table 8.3, “Available yum
clean
options” for a complete list of available configuration options.
Table 8.3. Available yum
clean
options
OptionDescriptionexpire-cacheeliminates time records of the metadata and mirrorlists download for each repository. This forces yum to revalidate the cache for each repository the next time it is used.packageseliminates any cached packages from the systemheaderseliminates all header files that previous versions of yum used for dependency resolutionmetadataeliminates all files that yum uses to determine the remote availability of packages. These metadata are downloaded again the next time yum is run.dbcacheeliminates the sqlite cache used for faster access to metadata. Using this option will force yum to download the sqlite metadata the next time it is run. This does not apply for repositories that contain only .xml data, in that case, sqlite data are deleted but without subsequent downloadrpmdbeliminates any cached data from the local rpmdbpluginsenabled plugins are forced to eliminate their cached dataallremoves all of the above
The expire-cache
option is most preferred from the above list. In many cases, it is a sufficient and much faster replacement for clean
all
.
yum 与rpm的区别和协作
rpm是一个底层管理工具,不能解决2个包之间的依赖关系,必须程序员手动安装依赖包
yum是一个上层管理工具,能自动安装依赖包
另外,yum安装的时候,有一个非常重要的是yum源的指定
yum源指的就是 远程服务器的地址,当yum客户端要安装包时,必须请求远程服务器,下载对应的包,这个是yum客户端请求哪个服务器地址呢?
很简单,就是根据从配置文件读取的,配置文件的路径是/etc/yum.repos.d
下面,我们简单的看一个mysql的yum源,如下:
[root@hecs-x-medium-2-linux-20201220090022 yum.repos.d]# cat mysql-community.repo
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-connectors-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-tools-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-5.6-community]
name=MySQL 5.6 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.6-community-el7-$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-5.7-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-$basearch/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
[mysql-8.0-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-$basearch/
enabled=0
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
各参数的含义分别为:
- [base]:容器名称,一定要放在[]中。
- name:容器说明,可以自己随便写。
- mirrorlist:镜像站点,这个可以注释掉。
- baseurl:我们的 yum 源服务器的地址。默认是 CentOS 官方的 yum 源服务器,是可以使用的。如果你觉得慢,则可以改成你喜欢的 yum 源地址。
- enabled:此容器是否生效,如果不写或写成 enabled 则表示此容器生效,写成 enable=0 则表示此容器不生效。
- gpgcheck:如果为 1 则表示 RPM 的数字证书生效;如果为 0 则表示 RPM 的数字证书不生效。
- gpgkey:数字证书的公钥文件保存位置。不用修改。
通过rpm的方式指定yun源
通过上面的知识,我们知道了yum源,那么yum源怎么获取呢?
除了手动敲,这里介绍一个使用rpm的方式指定yum源
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
上面rpm的作用就是:将包添加到了 yum repo 列表之中。
我们进入 cd /etc/yum.repos.d 可以看到已经被我们安装上的 nginx.repo 这个repo
现在,查看现在跟 nginx相关的 yum repo情况
[root@hecs-x-medium-2-linux-20201220090022 yum.repos.d]# yum repolist all | grep nginx
!nginx/x86_64 nginx repo enabled: 212
这个时候如果使用 yum install 会默认安装现在 repo 里面最新的 nginx
下面需要重新加载下yum源
yum clean all
yum makecache
DNF
Yum 是 RPM 的前端工具,它管理依赖关系和资源库,然后使用 RPM 来安装、下载和删除包。
DNF 的名称不是首字母缩写词。这三个字母是“Dandified YUM”的缩写。
DNF 是对 YUM 的改写
查询:
dnf --version
dnf search cockpit
dnf info terminator
dnf list installed // 查询已安装的包
dnf repolist // 查询可用的软件仓库
安装:
dnf install cockpit
移除
dnf remove bigapp
dnf autoremove // 清理未使用的软件包