嘘~ 正在从服务器偷取页面 . . .

玩转YUM-30个YUM常用命令(一)


YUM是Yellowdog Updater,Modified的缩写,是一种基于Redhat操作系统的开源包管理工具。
Yum负责在包安装、删除和更新期间自动安装依赖包。 Yum使用Redhat包管理器(RPM),可以从
Yum存储库(RPM包集合)安装软件包,这些软件包可以在本地或通过网络连接访问。
在这里,我们将演示用于管理Linux上的包的YUM命令示例(CentOS / RHEL / Fedora)

1,使用YUM安装一个包

要安装RPM包,可以使用以下命令。可以使用空格分隔的多个包名。
在yum命令中添加 -y 参数将自动安装/删除/重新安装包,而无需进一步确认。

[root@localhost ~]# yum install vsftpd
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 3157.
Another app is currently holding the yum lock; waiting for it to exit…
The other application is: PackageKit
Memory : 262 M RSS (1.6 GB VSZ)
Started: Tue Sep 25 12:37:23 2018 - 00:12 ago
State : Sleeping, pid: 3157
Another app is currently holding the yum lock; waiting for it to exit…
The other application is: PackageKit
Memory : 262 M RSS (1.6 GB VSZ)
Started: Tue Sep 25 12:37:23 2018 - 00:14 ago
State : Sleeping, pid: 3157
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
Resolving Dependencies
–> Running transaction check
—> Package vsftpd.x86_64 0:3.0.2-22.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size
Installing:
vsftpd x86_64 3.0.2-22.el7 base 169 k
Transaction Summary
Install 1 Package
Total download size: 169 k
Installed size: 348 k
Is this ok [y/d/N]: y
Downloading packages:
vsftpd-3.0.2-22.el7.x86_64.rpm 169 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : vsftpd-3.0.2-22.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-22.el7.x86_64 1/1
Installed:
vsftpd.x86_64 0:3.0.2-22.el7
Complete!
[root@localhost ~]#

2,用YUM删除包

要删除任何包,运行以下命令。可以使用空格分隔的多个包名。

[root@localhost ~]# yum remove vsftpd
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
–> Running transaction check
—> Package vsftpd.x86_64 0:3.0.2-22.el7 will be erased
–> Finished Dependency Resolution
Dependencies Resolved

Package Arch Version Repository Size
Removing:
vsftpd x86_64 3.0.2-22.el7 @base 348 k
Transaction Summary
Remove 1 Package
Installed size: 348 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : vsftpd-3.0.2-22.el7.x86_64 1/1
Verifying : vsftpd-3.0.2-22.el7.x86_64 1/1
Removed:
vsftpd.x86_64 0:3.0.2-22.el7
Complete!
[root@localhost ~]#

3,使用YUM更新包

要将任何包更新到最新版本,运行以下命令。可以使用空格分隔的多个包名。

[root@localhost ~]# yum update sudo
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
Resolving Dependencies
–> Running transaction check
—> Package sudo.x86_64 0:1.8.19p2-13.el7 will be updated
—> Package sudo.x86_64 0:1.8.19p2-14.el7_5 will be an update
–> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size
Updating:
sudo x86_64 1.8.19p2-14.el7_5 updates 1.1 M
Transaction Summary
Upgrade 1 Package
Total size: 1.1 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : sudo-1.8.19p2-14.el7_5.x86_64 1/2
Cleanup : sudo-1.8.19p2-13.el7.x86_64 2/2
Verifying : sudo-1.8.19p2-14.el7_5.x86_64 1/2
Verifying : sudo-1.8.19p2-13.el7.x86_64 2/2
Updated:
sudo.x86_64 0:1.8.19p2-14.el7_5
Complete!
[root@localhost ~]#

4,使用YUM降级包

要使用yum命令降级包,运行以下命令。这个命令将把包恢复到以前的版本。
只有当存储库具有上述包的以前版本时,它才能工作。
例如:降低上一个例子中刚刚更新的sudo包的版本。

[root@localhost ~]# yum downgrade sudo
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
Resolving Dependencies
–> Running transaction check
—> Package sudo.x86_64 0:1.8.19p2-13.el7 will be a downgrade
—> Package sudo.x86_64 0:1.8.19p2-14.el7_5 will be erased
–> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size
Downgrading:
sudo x86_64 1.8.19p2-13.el7 base 1.1 M
Transaction Summary
Downgrade 1 Package
Total download size: 1.1 M
Is this ok [y/d/N]: y
Downloading packages:
sudo-1.8.19p2-13.el7.x86_64.rpm 1.1 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : sudo-1.8.19p2-13.el7.x86_64 1/2
Cleanup : sudo-1.8.19p2-14.el7_5.x86_64 2/2
Verifying : sudo-1.8.19p2-13.el7.x86_64 1/2
Verifying : sudo-1.8.19p2-14.el7_5.x86_64 2/2
Removed:
sudo.x86_64 0:1.8.19p2-14.el7_5
Installed:
sudo.x86_64 0:1.8.19p2-13.el7
Complete!
[root@localhost ~]#

5,用YUM重新安装一个包

可以使用以下命令重新安装RPM,以解决安装问题

[root@localhost ~]# yum reinstall sudo
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.163.com
epel: mirrors.yun-idc.com
extras: mirrors.cn99.com
updates: mirrors.cn99.com
Resolving Dependencies
–> Running transaction check
—> Package sudo.x86_64 0:1.8.19p2-13.el7 will be reinstalled
–> Finished Dependency Resolution

Dependencies Resolved

Package Arch Version Repository Size
Reinstalling:
sudo x86_64 1.8.19p2-13.el7 base 1.1 M
Transaction Summary
Reinstall 1 Package
Total download size: 1.1 M
Installed size: 3.9 M
Is this ok [y/d/N]: y
Downloading packages:
sudo-1.8.19p2-13.el7.x86_64.rpm 1.1 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : sudo-1.8.19p2-13.el7.x86_64 1/1
Verifying : sudo-1.8.19p2-13.el7.x86_64 1/1
Installed:
sudo.x86_64 0:1.8.19p2-13.el7
Complete!
[root@localhost ~]#

6,通过YUM查看包

使用下面的命令来确认包是否已经安装或者是否可用。
输出将具有安装包的存储库名称。如果还没有安装,则输出将具有可用于安装包的存储库的名称。

已经安装的包
[root@localhost ~]# yum list tar
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
Installed Packages
tar.x86_64 2:1.26-34.el7 @anaconda
[root@localhost ~]#

可用的包
[root@localhost ~]# yum list httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
Available Packages
httpd.x86_64 2.4.6-80.el7.centos.1 updates
[root@localhost ~]#

7,列出已经安装的包

使用下面的命令查看系统上安装的软件包列表。
[root@localhost ~]# yum list installed less

8,列出可以安装的包

使用下面的命令查看系统上可以安装的软件包列表。
[root@localhost ~]# yum list available less

9,使用YUM查找/搜索包

使用以下命令搜索包。命令将简单地列出包含给定短语的包。
[root@localhost ~]# yum search telnet
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
================================ N/S matched: telnet =================================
dcap-tunnel-telnet.x86_64 : Telnet tunnel for dCache
libguac-client-telnet.x86_64 : Telnet support for guacd
libtelnet.x86_64 : TELNET protocol parsing framework
libtelnet-devel.x86_64 : Header files for libtelnet
libtelnet-utils.x86_64 : TELNET utility programs from libtelnet
perl-Net-Telnet.noarch : Net-Telnet Perl module
telnet.x86_64 : The client program for the Telnet remote login protocol
telnet-server.x86_64 : The server program for the Telnet remote login protocol
procServ.x86_64 : Process server with telnet console and log access
putty.x86_64 : SSH, Telnet and Rlogin client
tn5250.i686 : 5250 Telnet protocol and Terminal
tn5250.x86_64 : 5250 Telnet protocol and Terminal
Name and summary matches only, use “search all” for everything.
[root@localhost ~]#

10,找到哪个包提供了YUM的文件

这个命令将帮助您找到提供文件的包。例如:让我们找到哪个包提供了date命令。

[root@localhost ~]# yum provides date
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile

Webmin: download.webmin.com
base: mirrors.huaweicloud.com
epel: mirrors.yun-idc.com
extras: mirrors.huaweicloud.com
updates: mirrors.huaweicloud.com
Webmin/filelists 9.0 MB 00:05:08
base/7/x86_64/filelists_db 6.9 MB 00:00:01
epel/x86_64/filelists 10 MB 00:00:01
extras/7/x86_64/filelists_db 596 kB 00:00:00
updates/7/x86_64/filelists_db 2.9 MB 00:00:00
coreutils-8.22-21.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts
Repo : base
Matched from:
Filename : /usr/bin/date

coreutils-8.22-21.el7.x86_64 : A set of basic GNU tools commonly used in shell scripts
Repo : @anaconda
Matched from:
Filename : /usr/bin/date
[root@localhost ~]#


文章作者: kclouder
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 kclouder !
  目录