用于软件包管理的21个Linux YUM命令
FROM:http://os.51cto.com/art/201309/411895.htm
YUM(Yellowdog Updater Modified)是一款開源命令行及圖形化軟件包管理工具,面向基于RPM(紅帽軟件包管理器)的Linux系統。本文中將探討如何使用紅帽公司開發的YUM(Yellowdog Updater Modified)工具,安裝、更新、移除和查找軟件包,并管理軟件包和軟件庫。
我們在本文中將學習如何使用紅帽公司開發的YUM(Yellowdog Updater Modified)工具,安裝、更新、移除和查找軟件包,并管理軟件包和軟件庫。本文中顯示的示例命令都在我們的CentOS 6.3服務器上進行了實際測試,你可以將這些材料用于學習、認證,或者僅僅為了琢磨如何安裝新的軟件包,確保系統版本最新。本文的基本要求是,你對這些命令要有一個基本的了解,還要有一個正常運行的Linux操作系統,那樣才可以探究和執行下面所列的所有命令。
YUM到底是啥東東?
YUM(Yellowdog Updater Modified)是一款開源命令行及圖形化軟件包管理工具,面向基于RPM(紅帽軟件包管理器)的Linux系統。它讓廣大用戶和系統管理員可以在系統上輕松地安裝、更新、移除或搜索軟件包。它由Seth Vidal開發和發布,采用了GPL(通用公共許可證),是一款開源工具。這意味著,誰都可以下載和訪問代碼,以修復軟件錯誤,開發定制的軟件包。YUM通過解決軟件包的依賴項問題,使用眾多的第三方軟件庫來自動安裝軟件包。
1. 使用Yum安裝軟件包
想安裝一個名為Firefox 14的軟件包,只要運行下面這個命令,它會自動尋找并安裝Firefox瀏覽器的所有必要依賴項。
1 # yum remove firefox 2 Loaded plugins: fastestmirror 3 Setting up Remove Process 4 Resolving Dependencies 5 --> Running transaction check 6 ---> Package firefox.i686 0:10.0.6-1.el6.centos set to be erased 7 --> Finished Dependency Resolution 8 Dependencies Resolved 9 ===========================================Package Arch Version Repository Size 10 ===========================================Removing: 11 firefox i686 10.0.6-1.el6.centos @updates 23 M 12 Transaction Summary 13 =========================================== 14 Remove 1 Package(s) 15 Reinstall 0 Package(s) 16 Downgrade 0 Package(s) 17 Is this ok [y/N]: y 18 Downloading Packages: 19 Running rpm_check_debug 20 Running Transaction Test 21 Transaction Test Succeeded 22 Running Transaction 23 Erasing:firefox-10.0.6-1.el6.centos.i686 1/1 24 Removed: 25 firefox.i686 0:10.0.6-1.el6.centos 26 Complete!同樣,上述命令會先要求予以確認,然后再移除軟件包。想禁用確認提示,只要添加選項-y,如下所示。
?
# yum -y remove firefox?
3. 使用Yum更新軟件包
?
假設你有過時版本的MySQL軟件包,想把它更新到最新的穩定版本。只要運行下面這個命令,它就會自動解決所有的依賴項問題,并安裝依賴項。
1 # yum update mysql 2 Loaded plugins: fastestmirror 3 Dependencies Resolved 4 ===========================================Package Arch Version Repository Size 5 ===========================================Updating: 6 vsftpd i386 2.0.5-24.el5_8.1 updates 144 k 7 Transaction Summary 8 Install 0 Package(s) 9 Upgrade 1 Package(s) 10 Total size: 144 k 11 Is this ok [y/N]: y 12 Downloading Packages: 13 Running rpm_check_debug 14 Running Transaction Test 15 Finished Transaction Test 16 Transaction Test Succeeded 17 Running Transaction 18 Updating : vsftpd 1/2 19 Cleanup : vsftpd 2/2 20 Updated: 21 vsftpd.i386 0:2.0.5-24.el5_8.1 22 Complete!4. 使用Yum列出軟件包
使用list函數,可搜索帶名稱的特定軟件包。比如說,想搜索一個名為openssh的軟件包,使用該命令。
1 # yum list openssh 2 Loaded plugins: fastestmirror 3 Loading mirror speeds from cached hostfile 4 * base: mirror.neu.edu.cn 5 * epel: mirror.neu.edu.cn 6 * extras: mirror.neu.edu.cn 7 * rpmforge: mirror.nl.leaseweb.net 8 * updates: mirror.nus.edu.sg 9 Installed Packages 10 openssh.i386 4.3p2-72.el5_6.3 installed 11 Available Packages 4.3p2-82.el5 base想讓你的搜索更精確,明確軟件包名稱的版本,如果你知道的話。比如說,想搜索軟件包的特定版本openssh-4.3p2 ,使用該命令。
1 # yum list openssh-4.3p25. 使用Yum搜索軟件包
要是你不記得軟件包的確切名稱,那么可以使用search函數,搜索與指定軟件包的名稱相匹配的所有可用軟件包。比如說,想搜索與vsftpd這個單詞匹配的所有軟件包。
1 # yum search vsftpd 2 Loaded plugins: fastestmirror 3 Loading mirror speeds from cached hostfile 4 * base: mirror.neu.edu.cn 5 * epel: mirror.neu.edu.cn 6 * extras: mirror.neu.edu.cn 7 * rpmforge: mirror.nl.leaseweb.net 8 * updates: ftp.iitm.ac.in 9 ============================== Matched: vsftpd ======================== 10 ccze.i386 : A robust log colorizer 11 pure-ftpd-selinux.i386 : SELinux support for Pure-FTPD 12 vsftpd.i386 : vsftpd - Very Secure Ftp Daemon?
6. 使用Yum獲取軟件包信息
假設你想在安裝軟件包之前先知道它的信息。想獲得某軟件包的信息,只要執行下面這個命令。
1 # yum info firefox 2 Loaded plugins: fastestmirror 3 Loading mirror speeds from cached hostfile 4 * base: mirror.neu.edu.cn 5 * epel: mirror.neu.edu.cn 6 * extras: mirror.neu.edu.cn 7 * rpmforge: mirror.nl.leaseweb.net 8 * updates: ftp.iitm.ac.in 9 Available Packages 10 Name : firefox 11 Arch : i386 12 Version : 10.0.6 13 Release : 1.el5.centos 14 Size : 20 M 15 Repo : updates 16 Summary : Mozilla Firefox Web browser 17 URL : http://www.mozilla.org/projects/firefox/ 18 License : MPLv1.1 or GPLv2+ or LGPLv2+ 19 Description : Mozilla Firefox is an open-source web browser, designed for standards 20 : compliance, performance and portability7. 使用Yum列出所有的可用軟件包
想列出Yum數據庫中所有的可用軟件包,使用下面這個命令。
1 # yum list | less8. 使用Yum列出所有的已安裝軟件包
想列出系統上所有的已安裝軟件包,只要執行下面這個命令,它會顯示所有的已安裝軟件包。
1 # yum list installed | less?
9. Yum Provides函數
Yum provides函數用于查找某個特定文件屬于哪個軟件包。比如說,如果你想知道含有/etc/httpd/conf/httpd.conf文件的軟件包的名稱。
1 # yum provides /etc/httpd/conf/httpd.conf 2 Loaded plugins: fastestmirror 3 httpd-2.2.3-63.el5.centos.i386 : Apache HTTP Server 4 Repo : base 5 Matched from: 6 Filename : /etc/httpd/conf/httpd.conf 7 httpd-2.2.3-63.el5.centos.1.i386 : Apache HTTP Server 8 Repo : updates 9 Matched from: 10 Filename : /etc/httpd/conf/httpd.conf 11 httpd-2.2.3-65.el5.centos.i386 : Apache HTTP Server 12 Repo : updates 13 Matched from: 14 Filename : /etc/httpd/conf/httpd.conf 15 httpd-2.2.3-53.el5.centos.1.i386 : Apache HTTP Server 16 Repo : installed 17 Matched from: 18 Other : Provides-match: /etc/httpd/conf/httpd.conf10. 使用Yum檢查可用更新版
想找出你系統上有多少已安裝軟件包有可用更新版,只要使用下面這個命令。
1 # yum check-update11. 使用Yum更新系統
想確保系統版本最新,打上了所有的安全補丁和二進制軟件包更新,只要運行下面這個命令。它會為你的系統安裝所有最新的補丁和安全更新版。
1 # yum update12. 列出所有的可用群組軟件包
在Linux中,軟件包數量與特定群組捆綁在一起。你可以安裝某個群組,它就會安裝屬于該群組的所有相關軟件包,用不著使用Yum安裝單個軟件包。比如說,想列出所有的可用群組,只要執行下面這個命令。
1 # yum grouplist 2 Installed Groups: 3 Administration Tools 4 DNS Name Server 5 Dialup Networking Support 6 Editors 7 Engineering and Scientific 8 FTP Server 9 Graphics 10 Java Development 11 Legacy Network Server 12 Available Groups: 13 Authoring and Publishing 14 Base 15 Beagle 16 Cluster Storage 17 Clustering 18 Development Libraries 19 Development Tools 20 Eclipse 21 Educational Software 22 KDE (K Desktop Environment) 23 KDE Software Development13. 安裝群組軟件包
想安裝某個軟件包群組,我們使用選項groupinstall。比如說,想安裝"MySQL Database",只要執行下面這個命令。
1 # yum groupinstall 'MySQL Database' 2 Dependencies Resolved 3 ==================================================================Package Arch Version Repository Size 4 ==================================================================Updating: 5 unixODBC i386 2.2.11-10.el5 base 290 k 6 Installing for dependencies: 7 unixODBC-libs i386 2.2.11-10.el5 base 551 k 8 Transaction Summary 9 ==================================================================Install 1 Package(s) 10 Upgrade 1 Package(s) 11 Total size: 841 k 12 Is this ok [y/N]: y 13 Downloading Packages: 14 Running rpm_check_debug 15 Running Transaction Test 16 Finished Transaction Test 17 Transaction Test Succeeded 18 Running Transaction 19 Installing : unixODBC-libs 1/3 20 Updating : unixODBC 2/3 21 Cleanup : unixODBC 3/3 22 Dependency Installed: 23 unixODBC-libs.i386 0:2.2.11-10.el5 24 Updated: 25 unixODBC.i386 0:2.2.11-10.el5 26 Complete!14. 更新群組軟件包
想更新任何現有的已安裝群組軟件包,只要運行下面這個命令,如下所示。
1 # yum groupupdate 'DNS Name Server' 2 Dependencies Resolved 3 ==================================================================Package Arch Version Repository Size 4 ================================================================== 5 Updating: 6 bind i386 30:9.3.6-20.P1.el5_8.2 updates 981 k 7 bind-chroot i386 30:9.3.6-20.P1.el5_8.2 updates 47 k 8 Updating for dependencies: 9 bind-libs i386 30:9.3.6-20.P1.el5_8.2 updates 864 k 10 bind-utils i386 30:9.3.6-20.P1.el5_8.2 updates 174 k 11 Transaction Summary 12 Install 0 Package(s) 13 Upgrade 4 Package(s) 14 Total size: 2.0 M 15 Is this ok [y/N]: y 16 Downloading Packages: 17 Running rpm_check_debug 18 Running Transaction Test 19 Finished Transaction Test 20 Transaction Test Succeeded 21 Running Transaction 22 Updating : bind-libs 1/8 23 Updating : bind 2/8 24 Updating : bind-chroot 3/8 25 Updating : bind-utils 4/8 26 Cleanup : bind 5/8 27 Cleanup : bind-chroot 6/8 28 Cleanup : bind-utils 7/8 29 Cleanup : bind-libs 8/8 30 Updated: 31 bind.i386 30:9.3.6-20.P1.el5_8.2 bind-chroot.i386 30:9.3.6-20.P1.el5_8.2 32 Dependency Updated: 33 bind-libs.i386 30:9.3.6-20.P1.el5_8.2 bind-utils.i386 30:9.3.6-20.P1.el5_8.2 34 Complete!15. 移除群組軟件包
想從系統刪除或移除任何現有的已安裝群組軟件包,只要使用下面這個命令。
1 # yum groupremove 'DNS Name Server' 2 Dependencies Resolved 3 ==========================================Package Arch Version Repository Size 4 ==========================================Removing: 5 bind i386 30:9.3.6-20.P1.el5_8.2 installed 2.1 M 6 bind-chroot i386 30:9.3.6-20.P1.el5_8.2 installed 0.0 7 Transaction Summary 8 ==========================================Remove 2 Package(s) 9 Reinstall 0 Package(s) 10 Downgrade 0 Package(s) 11 Is this ok [y/N]: y 12 Downloading Packages: 13 Running rpm_check_debug 14 Running Transaction Test 15 Finished Transaction Test 16 Transaction Test Succeeded 17 Running Transaction 18 Erasing : bind 1/2 19 warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave 20 Erasing : bind-chroot 2/2 21 Removed: 22 bind.i386 30:9.3.6-20.P1.el5_8.2 bind-chroot.i386 30:9.3.6-20.P1.el5_8.2 23 Complete!16. 列出啟用的Yum軟件庫
列出系統里面所有啟用的Yum軟件庫,使用下面這個選項。
1 # yum repolist 2 repo id repo name status 3 base CentOS-5 - Base enabled: 2,725 4 epel Extra Packages for Enterprise Linux 5 - i386 enabled: 5,783 5 extras CentOS-5 - Extras enabled: 282 6 mod-pagespeed mod-pagespeed enabled: 1 7 rpmforge RHEL 5 - RPMforge.net - dag enabled: 11,290 8 updates CentOS-5 - Updates enabled: 743 9 repolist: 20,824?
17. 列出所有啟用和禁用的Yum軟件庫
下面這個命令會顯示系統上所有啟用和禁用的yum軟件庫。
1 # yum repolist all 2 repo id repo name status 3 C5.0-base CentOS-5.0 - Base disabled 4 C5.0-centosplus CentOS-5.0 - Plus disabled 5 C5.0-extras CentOS-5.0 - Extras disabled 6 base CentOS-5 - Base enabled: 2,725 7 epel Extra Packages for Enterprise Linux 5 - i386 enabled: 5,783 8 extras CentOS-5 - Extras enabled: 282 9 repolist: 20,824?
18. 安裝來自特定軟件庫的軟件包
想安裝來自某個啟用或禁用的軟件庫的某個軟件包,必須在yum命令中使用-enablerepo選項。比如,想安裝PhpMyAdmin 3.5.2軟件包,只要執行這個命令。
1 # yum --enablerepo=epel install phpmyadmin 2 Dependencies Resolved 3 ================================================================== Package Arch Version Repository Size 4 ==================================================================Installing: 5 phpMyAdmin noarch 3.5.1-1.el6 epel 4.2 M 6 Transaction Summary 7 ==================================================================Install 1 Package(s) 8 Total download size: 4.2 M 9 Installed size: 17 M 10 Is this ok [y/N]: y 11 Downloading Packages: 12 phpMyAdmin-3.5.1-1.el6.noarch.rpm | 4.2 MB 00:25 13 Running rpm_check_debug 14 Running Transaction Test 15 Transaction Test Succeeded 16 Running Transaction 17 Installing : phpMyAdmin-3.5.1-1.el6.noarch 1/1 18 Verifying : phpMyAdmin-3.5.1-1.el6.noarch 1/1 19 Installed: 20 phpMyAdmin.noarch 0:3.5.1-1.el6 21 Complete!19. 交互式Yum外殼
Yum實用工具提供了一個自定義外殼,你可以在這個環境下執行多個命令。
1 # yum shell 2 Loaded plugins: fastestmirror 3 Setting up Yum Shell 4 > update httpd 5 Loading mirror speeds from cached hostfile 6 * base: mirrors.sin3.sg.voxel.net 7 * epel: ftp.riken.jp 8 * extras: mirrors.sin3.sg.voxel.net 9 * updates: mirrors.sin3.sg.voxel.net 10 Setting up Update Process 11 >?
20. 清理Yum緩存內容
默認情況下,yum將所有軟件庫中啟用軟件包的數據,連同每個子目錄保存在/var/cache/yum/中,想清除啟用軟件庫中的所有緩存文件,你要定期運行下面這個命令,清理所有緩存內容,并確保沒有任何東西在使用不必要的存儲空間。我們不想給出下面這個命令的輸出結果,因為我們想保持緩存數據的原來樣子。
1 # yum clean all21. 查看Yum的歷史記錄
想查看Yum命令的所有過去的事務,只要使用下面這個命令。
1 # yum history 2 Loaded plugins: fastestmirror 3 ID | Login user | Date and time | Action(s) | Altered 4 ------------------------------------------------------------------ 5 10 | root | 2012-08-11 15:19 | Install | 3 6 9 | root | 2012-08-11 15:11 | Install | 1 7 8 | root | 2012-08-11 15:10 | Erase | 1 EE 8 7 | root | 2012-08-10 17:44 | Install | 1 9 6 | root | 2012-08-10 12:19 | Install | 2 10 5 | root | 2012-08-10 12:14 | Install | 3 11 4 | root | 2012-08-10 12:12 | I, U | 13 E< 12 3 | root | 2012-08-09 13:01 | Install | 1 > 13 2 | root | 2012-08-08 20:13 | I, U | 292 EE 14 1 | System | 2012-08-08 17:15 | Install | 560 15 history list?
?
?
?
?
?
?
?
?
?
?
?
轉載于:https://www.cnblogs.com/wq920/p/3355053.html
總結
以上是生活随笔為你收集整理的用于软件包管理的21个Linux YUM命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux帮助信息获取
- 下一篇: MySQL的root默认密码修改