Linux下的yum怎麼升級?

  • 2020 年 3 月 17 日
  • 筆記

Linux下我們安裝軟體,可能會需要安裝各種包來支援,你可以從安裝介質中找到rpm,手動安裝,但最常用的,可能還是yum,省了很多煩惱。

但要知道yum同樣需要升級,yum怎麼升級?碰巧看到楊大師的一篇文章《LINUX環境下如何重建yum源並更新》,介紹了整個操作。

1. 備份默認的yum

# mv /etc/yum.repos.d /etc/yum.repos.d.backup

2. 設置新的yum目錄

# mkdir /etc/yum.repos.d

3. 下載阿里yum配置到該目錄中,用wget,進行下載,

# yum install -y wget  # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

4. 重建快取

yum clean all執行效果,

[root@ethanyang yum.repos.d]# yum clean all  Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager  This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.  Cleaning repos: base centosplus extras updates  Cleaning up everything

yum makecache執行效果,

[root@ethanyang yum.repos.d]# yum makecache  Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager  This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.  base                                                                                                            | 3.6 kB  00:00:00  centosplus                                                                                                      | 2.9 kB  00:00:00  extras                                                                                                          | 2.9 kB  00:00:00  updates                                                                                                         | 2.9 kB  00:00:00  (1/13): base/x86_64/group_gz                                                                                    | 165 kB  00:00:00  (2/13): base/x86_64/filelists_db                                                                                | 7.3 MB  00:00:08  (3/13): base/x86_64/primary_db                                                                                  | 6.0 MB  00:00:08  (4/13): base/x86_64/other_db                                                                                    | 2.6 MB  00:00:02  (5/13): centosplus/x86_64/filelists_db                                                                          | 1.2 MB  00:00:02  (6/13): centosplus/x86_64/other_db                                                                              |  69 kB  00:00:00  (7/13): centosplus/x86_64/primary_db                                                                            | 2.7 MB  00:00:03  (8/13): extras/x86_64/filelists_db                                                                              | 216 kB  00:00:00  (9/13): extras/x86_64/other_db                                                                                  | 106 kB  00:00:00  (10/13): extras/x86_64/primary_db                                                                               | 164 kB  00:00:01  (11/13): updates/x86_64/filelists_db                                                                            | 4.0 MB  00:00:03  (12/13): updates/x86_64/other_db                                                                                | 493 kB  00:00:00  (13/13): updates/x86_64/primary_db                                                                              | 6.7 MB  00:00:06  Metadata Cache Created  [root@ethanyang yum.repos.d]#

5. 升級所有包

yum update -y

注意:

(1) 第一次運行yum安裝軟體前,建議更新yum。

(2) yum update -y改變軟體設置和系統設置,系統版本內核都升級,需幾分鐘耐心等待。

另外,熟悉Linux的親,可能還熟悉升級方式有upgrade,這裡簡述下區別:

yum -y update:升級所有包同時,也升級軟體和系統內核; yum -y upgrade:只升級所有包,不升級軟體和系統內核,軟體和內核保持原樣。