Linux 套件管理 – yum

Loading

測試環境為 CentOS7 x86_64

yum 主要的設定檔為 /etc/yum.conf ,如果要新增 repos 可以把檔案寫在 /etc/yum.repos.d/ 目錄下面.如果你的本地端網路環境有建 CentOS7 的 repos ,可以直接把設定寫在 /etc/yum.conf

[root@localhost ~]$ vi /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

[CentOS7]
name = CentOS7
baseurl = http://172.16.0.3/centos7-amd64/
gpgkey = https://172.16.0.3/centos7-amd64/RPM-GPG-KEY-CentOS-7
gpgcheck=1
  • # yum update
    更新套件名稱.

    [root@localhost ~]$ yum update
    
  • # yum install
    安裝套件名稱.

    [root@localhost ~]$ yum install MariaDB-Galera-server
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: ftp.tc.edu.tw
     * extras: ftp.tc.edu.tw
     * updates: ftp.tc.edu.tw
    No package MariaDB-Galera-server available.
    Error: Nothing to do
    

    不是所有的套件都可以在預設的 yum repos 裡面,像是 MariaDB 就需要新增加 MariaDB 的 YUM 網址.目前版本有分 5.5 以及 10.1 (MariaDB server 含 Galera 功能).我用的是 5.5 版本 (請先上 MariaDB 官方網站查詢版本與 baseurl, gpgkey),並新增 yum repos 設定.

    [root@localhost ~]# vi /etc/yum.repos.d/MariaDB.repo
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/5.5.51/centos7-amd64/
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
    
    [root@localhost ~]# yum update
    Loaded plugins: fastestmirror
    mariadb                                                  | 2.9 kB     00:00     
    mariadb/primary_db                                         |  19 kB   00:00     
    Loading mirror speeds from cached hostfile
     * base: centos.cs.nctu.edu.tw
     * extras: centos.cs.nctu.edu.tw
     * updates: centos.cs.nctu.edu.tw
    Resolving Dependencies
    ...
    [root@localhost ~]# yum install MariaDB-Galera-server
    
  • # yum grouplist , # yum groups install
    如果安裝 CentOS7 是最小安裝時是沒有桌面系統的,之後要再額外安裝桌面系統會很麻煩.這時候可以透過 group install 的方式.

    [root@localhost ~]$ yum grouplist
    Loaded plugins: fastestmirror
    There is no installed groups file.
    Maybe run: yum groups mark convert (see man yum)
    Loading mirror speeds from cached hostfile
     * base: centos.cs.nctu.edu.tw
     * extras: centos.cs.nctu.edu.tw
     * updates: centos.cs.nctu.edu.tw
    Available environment groups:
       Minimal Install
       Compute Node
       Infrastructure Server
       File and Print Server
       Basic Web Server
       Virtualization Host
       Server with GUI
       GNOME Desktop
       KDE Plasma Workspaces
       Development and Creative Workstation
    Available Groups:
       Compatibility Libraries
       Console Internet Tools
       Development Tools
       Graphical Administration Tools
       Legacy UNIX Compatibility
       Scientific Support
       Security Tools
       Smart Card Support
       System Administration Tools
       System Management
    
    [root@localhost ~]$ yum groups install "GNOME Desktop"
    
  • # yum remove
    移除套件名稱.

    [root@localhost ~]$ yum remove MariaDB-Galera-server
    
  • # yum search
    搜尋套件名稱.

    [root@localhost ~]$ yum search MariaDB-Galera-server
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: centos.cs.nctu.edu.tw
     * extras: centos.cs.nctu.edu.tw
     * updates: centos.cs.nctu.edu.tw
    ====================== N/S matched: MariaDB-Galera-server ======================
    MariaDB-Galera-server.x86_64 : MariaDB: a very fast and robust SQL database
                                 : server
    
      Name and summary matches only, use "search all" for everything.
    

    可以加參數 all 搜尋更多

    [root@localhost ~]$ yum search all MariaDB-Galera-server
    

    但是很多的時候我們根本不知道套件名稱怎麼辦呢!!可以利用下面的 #yum whatprovides

  • # yum whatprovides “*command”
    查詢未安裝的程式是由哪一個套件裡提供的.搜尋 /sbin/ifconfig 是哪一個套件提供的.

    [root@localhost ~]$yum whatprovides "*ifconfig"
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
     * base: mirror01.idc.hinet.net
     * extras: ftp.twaren.net
     * updates: ftp.twaren.net
    hypervkvpd-0-0.26.20150402git.el7.x86_64 : HyperV key value pair (KVP) daemon
    Repo        : base
    Matched from:
    Filename    : /usr/libexec/hypervkvpd/hv_set_ifconfig
     
    net-tools-2.0-0.17.20131004git.el7.x86_64 : Basic networking tools
    Repo        : base
    Matched from:
    Filename    : /sbin/ifconfig
     
    python-ethtool-0.8-5.el7.x86_64 : Ethernet settings python bindings
    Repo        : base
    Matched from:
    Filename    : /usr/sbin/pifconfig
     
    zsh-5.0.2-14.el7.x86_64 : Powerful interactive shell
    Repo        : base
    Matched from:
    Filename    : /usr/share/zsh/5.0.2/functions/_ifconfig
     
    zsh-5.0.2-14.el7_2.2.x86_64 : Powerful interactive shell
    Repo        : updates
    Matched from:
    Filename    : /usr/share/zsh/5.0.2/functions/_ifconfig
    
  • # yum clean
    清除 /var/cache/yum 下載的暫存套件檔,使用 #yum clean all 可以一次就給他清乾淨.

    [root@localhost ~]$ yum clean all
    Loaded plugins: fastestmirror
    Cleaning repos: base extras mariadb nginx updates
    Cleaning up everything
    Cleaning up list of fastest mirrors
    
  • # yum list updates
    列出所有可供更新的套件.

    [root@localhost ~]$ yum list updates
    Loaded plugins: fastestmirror
    base                                                     | 3.6 kB     00:00     
    extras                                                   | 3.4 kB     00:00     
    mariadb                                                  | 2.9 kB     00:00     
    nginx                                                    | 2.9 kB     00:00     
    updates                                                  | 3.4 kB     00:00     
    (1/6): base/7/x86_64/group_gz                              | 155 kB   00:01     
    (2/6): nginx/x86_64/primary_db                             |  24 kB   00:01     
    (3/6): mariadb/primary_db                                  |  19 kB   00:01     
    (4/6): extras/7/x86_64/primary_db                          | 168 kB   00:05     
    (5/6): base/7/x86_64/primary_db                            | 5.6 MB   00:15     
    (6/6): updates/7/x86_64/primary_db                         | 6.4 MB   00:24     
    Determining fastest mirrors
     * base: ftp.yzu.edu.tw
     * extras: ftp.yzu.edu.tw
     * updates: ftp.yzu.edu.tw
    
  • # yum list installed
    列出所有已經安裝的套件.

    [root@localhost ~]$ yum list installed
    

遇過的問題
更新時出現以下的錯誤訊息.

[root@localhost ~]# yum update
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 3020.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
    Memory :  59 M RSS (1.4 GB VSZ)
    Started: Tue Dec 10 00:04:50 2019 - 00:08 ago
    State  : Running, pid: 3020

packagekit 這個 Tool 會自動幫忙更新,想要改成手動更新,可以直接把該服務停掉.

[root@localhost ~]# systemctl stop packagekit
沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料