【Linux】Yum介紹與常見用法

本文主要介紹 Yum 的相關知識與 Yum 命令的常見用法。

1. Yum概述
對於 Yum(yellowdog update modified),引用官網的概述,如下:

Yum is an automatic updater and package installer/remover for rpm systems. It automatically computes dependencies and figures out what things should occur to install packages. It makes it easier to maintain groups of machines without having to manually update each one using rpm. Yum has a plugin interface for adding simple features. Yum can also be used from other python programs via its module inteface.

2. 設置Yum源
關於 Yum 源,官網解釋如下:

A package repository used by yum is simply a directory with one or more RPMs plus some "meta information" used by yum to be able to easily access information (dependencies, file lists, etc.) for the RPMs. Yum can then to access this directory over ftp/http or a file URI (including over NFS).

2.1 添加Yum源
2.1.1 添加centos 7的阿里源
1. 進入 yum 源的存儲路徑中:

cd /etc/yum.repos.d/
2. 使用 wget 或 curl 命令下載 CentOS 7 的阿里源,如下:

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

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3. 運行下面的命令,清除並重新生成 yum 緩存:

yum clean all
yum makecache
2.1.2 添加EPEL源
EPEL(Extra Packages for Enterprise Linux)是由 Fedora 社區打造的、爲 RHEL 及其衍生髮行版(如 CentOS 等)提供高質量軟件包的項目。安裝了 EPEL 源之後,就像在 Fedora 上一樣,通過“yum install 軟件包名”,即可安裝很多之前需要編譯安裝的軟件、常用的軟件以及一些比較流行的軟件,比如現在流行的 nginx、redis 等。安裝了EPEL源之後,都可以使用 EPEL 很方便的安裝更新。

在安裝了 CentOS 7 的阿里源(或其他可用源)之後,我們可以直接通過下面的命令安裝 EPEL 的 yum 源:

yum install epel-release
執行完上述操作後,能夠在 yum 源路徑 /etc/yum.repos.d 下看見 epel 的倉庫文件,如下:

然後重新生成 yum 緩存,即可使用 epel 源了。

3. 常見用法
1. 搜索軟件包:

yum search packagename
2. 安裝軟件包:

yum install packagename/groupname
3. 卸載軟件包:

yum erase packagename/groupname
4. -y 選項:在交互過程中,對於所有的問題回答“yes”

5. 下載軟件包(使用 yumdownloader ):

1)安裝 yum-utils ,如下:

yum install yum-utils
2)使用 yumdownloader 命令下載指定包:

yumdownloader jsoncpp-devel.x86_64 --resolve
說明: --resolve 選項會同時下載指定包的依賴包。

 

4. 常見問題
1. 在使用 yum 命令安裝軟件包的過程中,出現主機名解析失敗的問題。例如:Could not resolve host: pkg.jenkins.io; Unknown error

嘗試以下幾種解決方法:

1)通過如下命令更新yum緩存信息:

yum clean all
yum makecache
之後,再次嘗試使用yum命令安裝相關的軟件包。

2)使用yum搜索命令,先確認待安裝軟件包的具體名稱,然後再使用yum命令安裝搜索出來的軟件包名字。例如:

yum search jenkins
運行上面的命令,能夠搜索出軟件jenkins的詳細信息,如下:

jenkins.noarch : Jenkins Automation Server
所以,可以根據上述信息,使用yum命令安裝jenkins,如下:

yum install jenkins.noarch
注意:上面的命令中使用的是“yum install jenkins.noarch”,而非“yum install jenkins”。
————————————————
版權聲明:本文爲CSDN博主「liitdar」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/liitdar/article/details/80266569

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章