【CentOS 7筆記28】,yum的用法#

shallow丿ovelinux


yum工具操做

  1. yum list #列出可用的全部軟件包
[root@localhost ~]# ls /etc/yum.repos.d/CentOS-
CentOS-Base.repo       CentOS-Debuginfo.repo  CentOS-Media.repo      CentOS-Vault.repo
CentOS-CR.repo         CentOS-fasttrack.repo  CentOS-Sources.repo  
[root@localhost ~]# vi /etc/yum.repos.d/CentOS-Base.repo
	# CentOS-Base.repo
	#
	# The mirror system uses the connecting IP address of the client and the
	# update status of each mirror to pick mirrors that are updated to and
	# geographically close to the client.  You should use this for CentOS updates
	# unless you are manually picking other mirrors.
	#
	# If the mirrorlist= does not work for you, as a fall back you can try the
	# remarked out baseurl= line instead.
	#
	#

	[base]
	name=CentOS-$releasever - Base
	mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
	#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
	gpgcheck=1
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

	#released updates
	[updates]
	name=CentOS-$releasever - Updates
	mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
	#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
	gpgcheck=1
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

	#additional packages that may be useful
	[extras]
	name=CentOS-$releasever - Extras
	mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
	#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
	gpgcheck=1
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

	#additional packages that extend functionality of existing packages
	[centosplus]
	name=CentOS-$releasever - Plus
	mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
	#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
	gpgcheck=1
	enabled=0
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

CentOS-Base.repo,相似於一個容器,將全部rpm包放置於此,其中[base]就是yum的倉庫名字git

  1. yum install [-y] 包名
[root@localhost ~]# yum install texlive
	Loaded plugins: fastestmirror
	base                                                                        | 3.6 kB  00:00:00     
	extras                                                                      | 3.4 kB  00:00:00     
	updates                                                                     | 3.4 kB  00:00:00     
	Loading mirror speeds from cached hostfile
	 * base: mirrors.zju.edu.cn
	 * extras: mirrors.zju.edu.cn
	 * updates: mirrors.zju.edu.cn
	Resolving Dependencies
	--> Running transaction check
	---> Package texlive.x86_64 2:2012-38.20130427_r30134.el7 will be installed
	--> Processing Dependency: texlive-scheme-basic for package: 2:texlive-2012-38.20130427_r30134.el7.x86_64
	
	……
	
	 texlive-zapfchan                      noarch 2:svn28614.0-38.el7                    base    102 k
	 texlive-zapfding                      noarch 2:svn28614.0-38.el7                    base     65 k
	 zziplib                               x86_64 0.13.62-5.el7                          base     81 k

	Transaction Summary
	===================================================================================================
	Install  1 Package (+246 Dependent packages)

	Total download size: 123 M
	Installed size: 237 M
	Is this ok [y/d/N]: N
	Exiting on user command
	Your transaction was saved, rerun it with:
	 yum load-transaction /tmp/yum_save_tx.2017-11-14.03-35.L1YwuV.yumtx

若單用rpm安裝texlive包時,則還須要安裝246個依賴包。而使用yum工具同時能夠解決軟件的依賴關係,選項-y選項指的是對於每次詢問都以yes做回答。這裏Is this ok [y/d/N]:的d指的是隻下載全部軟件包,但並不安裝。github

  1. yum search 包名關鍵字 #搜索與包名相關的軟件包
[root@localhost ~]# yum search vim
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	 * base: mirrors.zju.edu.cn
	 * extras: mirrors.zju.edu.cn
	 * updates: mirrors.zju.edu.cn
	======================================== N/S matched: vim =========================================
	protobuf-vim.x86_64 : Vim syntax highlighting for Google Protocol Buffers descriptions
	vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
	vim-common.x86_64 : The common files needed by any version of the VIM editor
	vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
	vim-filesystem.x86_64 : VIM filesystem layout
	vim-minimal.x86_64 : A minimal version of the VIM editor

	  Name and summary matches only, use "search all" for everything.

搜索與vim相關的包,但同時這種搜索方式會大量與包名無關的東西,這時候能夠使用過濾命令來過濾一些無用的信息docker

[root@localhost ~]# yum list | grep 'vim'
	vim-minimal.x86_64                          2:7.4.160-2.el7            @anaconda
	protobuf-vim.x86_64                         2.5.0-8.el7                base     
	vim-X11.x86_64                              2:7.4.160-2.el7            base     
	vim-common.x86_64                           2:7.4.160-2.el7            base     
	vim-enhanced.x86_64                         2:7.4.160-2.el7            base     
	vim-filesystem.x86_64                       2:7.4.160-2.el7            base
  1. yum grouplist #列出全部組 yum groupinstall [-y] 組名 #安裝組套件
[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: mirrors.zju.edu.cn
	 * extras: mirrors.zju.edu.cn
	 * updates: mirrors.zju.edu.cn
	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
	Done

例如:vim

[root@localhost ~]# yum groupinstall 'Virtualization Host'
	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: mirrors.zju.edu.cn
	 * extras: mirrors.zju.edu.cn
	 * updates: mirrors.zju.edu.cn
	Warning: Group core does not have any packages to install.
	Resolving Dependencies
	--> Running transaction check
	---> Package abrt-addon-ccpp.x86_64 0:2.1.11-48.el7.centos will be installed
	--> Processing Dependency: abrt-libs = 2.1.11-48.el7.centos for package: abrt-addon-ccpp-2.1.11-48.el7.centos.x86_64

	……

	systemd                                 x86_64   219-42.el7_4.4                   updates   5.2 M
	 systemd-libs                            x86_64   219-42.el7_4.4                   updates   376 k
	 systemd-sysv                            x86_64   219-42.el7_4.4                   updates    70 k

	Transaction Summary
	===================================================================================================
	Install  70 Packages (+216 Dependent packages)
	Upgrade              (   5 Dependent packages)

	Total download size: 92 M
	Is this ok [y/d/N]: N
	Exiting on user command
	Your transaction was saved, rerun it with:
	 yum load-transaction /tmp/yum_save_tx.2017-11-14.04-31.EGR_5a.yumtx

安裝不一樣組就會安裝不一樣套件,不一樣類型組的rpm數量也就不一樣。centos

  1. yum remove [-y] 包名 #卸載軟件包以及全部依賴包

使用rpm -e卸載軟件包時,會提示依賴關係,在卸載此軟件包時必須卸載全部有依賴關係的包,而yum工具能夠徹底自動卸載軟件包以及全部依賴包app

[root@localhost ~]# rpm -e ppp
	error: Failed dependencies:
		ppp = 2.4.5 is needed by (installed) NetworkManager-1:0.9.9.1-13.git20140326.4dba720.el7.x86_64
[root@localhost ~]# yum remove ppp
	Loaded plugins: fastestmirror
	Resolving Dependencies
	--> Running transaction check
	---> Package ppp.x86_64 0:2.4.5-33.el7 will be erased
	--> Processing Dependency: ppp = 2.4.5 for package: 1:NetworkManager-0.9.9.1-13.git20140326.4dba720.el7.x86_64
	--> Running transaction check
	---> Package NetworkManager.x86_64 1:0.9.9.1-13.git20140326.4dba720.el7 will be erased
	--> Processing Dependency: NetworkManager(x86-64) = 1:0.9.9.1-13.git20140326.4dba720.el7 for package: 1:NetworkManager-tui-0.9.9.1-13.git20140326.4dba720.el7.x86_64
	--> Running transaction check
	---> Package NetworkManager-tui.x86_64 1:0.9.9.1-13.git20140326.4dba720.el7 will be erased
	--> Finished Dependency Resolution

	Dependencies Resolved

	===================================================================================================
	 Package                Arch       Version                                     Repository     Size
	===================================================================================================
	Removing:
	 ppp                    x86_64     2.4.5-33.el7                                @anaconda     852 k
	Removing for dependencies:
	 NetworkManager         x86_64     1:0.9.9.1-13.git20140326.4dba720.el7        @anaconda     5.9 M
	 NetworkManager-tui     x86_64     1:0.9.9.1-13.git20140326.4dba720.el7        @anaconda     253 k

	Transaction Summary
	===================================================================================================
	Remove  1 Package (+2 Dependent packages)

	Installed size: 7.0 M
	Is this ok [y/N]: N
	Exiting on user command
	Your transaction was saved, rerun it with:
	 yum load-transaction /tmp/yum_save_tx.2017-11-14.04-43.nJuUxJ.yumtx
  1. yum update [-y] 包名 #更新軟件包less

  2. yum provides "/*/命令"curl

[root@localhost ~]# yum provides "/*/vim"
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	 * base: mirrors.zju.edu.cn
	 * extras: mirrors.zju.edu.cn
	 * updates: mirrors.zju.edu.cn
	cmake-2.8.12.2-2.el7.x86_64 : Cross-platform make system
	Repo        : base
	Matched from:
	Filename    : /usr/share/cmake/editors/vim



	2:docker-unit-test-1.12.6-48.git0fdc778.el7.centos.x86_64 : Automates deployment of containerized
															  : applications - for running unit tests
	Repo        : extras
	Matched from:
	Filename    : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/runc-79c3939053c870fbb4de5484d98640d5ba028ef4/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/containerd-fa8fb3d455e1baf716f3131581f0ed8b07c573a6/vendor/src/github.com/docker/docker/contrib/syntax/vim



	2:docker-unit-test-1.12.6-55.gitc4618fb.el7.centos.x86_64 : Automates deployment of containerized
															  : applications - for running unit tests
	Repo        : extras
	Matched from:
	Filename    : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/runc-31a9f6e22729606814e9bcbcf9eeebc1887527cb/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/containerd-fa8fb3d455e1baf716f3131581f0ed8b07c573a6/vendor/src/github.com/docker/docker/contrib/syntax/vim



	2:docker-unit-test-1.12.6-61.git85d7426.el7.centos.x86_64 : Automates deployment of containerized
															  : applications - for running unit tests
	Repo        : extras
	Matched from:
	Filename    : /var/lib/docker-unit-test/runc-c5d311627d39439c5b1cc35c67a51c9c6ccda648/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/v1.10-migrator-c417a6a022c5023c111662e8280f885f6ac259be/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/docker-novolume-plugin-385ec70baac3ef356f868f391c8d7818140fbd44/Godeps/_workspace/src/github.com/docker/docker/contrib/syntax/vim
	Filename    : /var/lib/docker-unit-test/containerd-fa8fb3d455e1baf716f3131581f0ed8b07c573a6/vendor/src/github.com/docker/docker/contrib/syntax/vim



	git-1.8.3.1-11.el7.x86_64 : Fast Version Control System
	Repo        : base
	Matched from:
	Filename    : /usr/share/doc/git-1.8.3.1/contrib/vim



	git-1.8.3.1-12.el7_4.x86_64 : Fast Version Control System
	Repo        : updates
	Matched from:
	Filename    : /usr/share/doc/git-1.8.3.1/contrib/vim



	2:vim-common-7.4.160-2.el7.x86_64 : The common files needed by any version of the VIM editor
	Repo        : base
	Matched from:
	Filename    : /usr/share/vim



	2:vim-enhanced-7.4.160-2.el7.x86_64 : A version of the VIM editor which includes recent
										: enhancements
	Repo        : base
	Matched from:
	Filename    : /usr/bin/vim

而rpm -qf which vim用於查詢命令源哪一個已安裝的軟件包ide

yum搭建本地倉庫

[root@localhost ~]# ls /mnt
	CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
	EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@localhost ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
[root@localhost yum.repos.d]# ls
	CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
	CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@localhost yum.repos.d]# rm -rf ./*
[root@localhost yum.repos.d]# vi dvd.repo
	[dvd]
	name=install dvd
	baseurl=file:///mnt
	enable=1
	gpgcheck=0
[root@localhost yum.repos.d]# yum clean all
	Loaded plugins: fastestmirror
	Cleaning repos: dvd
	Cleaning up everything
	Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum list | less

其中dvd就是本地倉庫名字,帶@表示已安裝

[root@localhost yum.repos.d]# yum install GConf2
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	Resolving Dependencies
	--> Running transaction check
	---> Package GConf2.x86_64 0:3.2.6-8.el7 will be installed
	--> Processing Dependency: /usr/bin/killall for package: GConf2-3.2.6-8.el7.x86_64
	--> Running transaction check
	---> Package psmisc.x86_64 0:22.20-15.el7 will be installed
	--> Finished Dependency Resolution

	Dependencies Resolved

	==================================================================================================
	 Package               Arch                  Version                     Repository          Size
	==================================================================================================
	Installing:
	 GConf2                x86_64                3.2.6-8.el7                 dvd                1.0 M
	Installing for dependencies:
	 psmisc                x86_64                22.20-15.el7                dvd                141 k

	Transaction Summary
	==================================================================================================
	Install  1 Package (+1 Dependent package)

	Total download size: 1.1 M
	Installed size: 6.8 M
	Is this ok [y/d/N]: N
	Exiting on user command
	Your transaction was saved, rerun it with:
	 yum load-transaction /tmp/yum_save_tx.2017-11-14.05-25.euCvOB.yumtx

本地使用yum也能解決依賴關係

yum更換國內源

[root@localhost yum.repos.d]# rm -f dvd.repo 
[root@localhost yum.repos.d]# cp ../yum.repos.d.bak/* .
	cp: omitting directory ‘../yum.repos.d.bak/yum.repos.d’
[root@localhost yum.repos.d]# ls
	CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@localhost yum.repos.d]# rm -f CentOS-Base.repo 
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
若沒有安裝wget命令,則能夠使用curl -O
[root@localhost yum.repos.d]# curl -O http://mirrors.163.com/.help/CentOS7-Base-163.repo
	  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
	                                 Dload  Upload   Total   Spent    Left  Speed
	100  1572  100  1572    0     0   6179      0 --:--:-- --:--:-- --:--:--  6213
[root@localhost yum.repos.d]# ls
	CentOS7-Base-163.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@localhost yum.repos.d]# vi CentOS7-Base-163.repo
	# CentOS-Base.repo
	#
	# The mirror system uses the connecting IP address of the client and the
	# update status of each mirror to pick mirrors that are updated to and
	# geographically close to the client.  You should use this for CentOS updates
	# unless you are manually picking other mirrors.
	#
	# If the mirrorlist= does not work for you, as a fall back you can try the 
	# remarked out baseurl= line instead.
	#
	#
	[base]
	name=CentOS-$releasever - Base - 163.com
	#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
	baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
	gpgcheck=1
	gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

	#released updates
	[updates]
	name=CentOS-$releasever - Updates - 163.com
	#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
	baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
	gpgcheck=1
	gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

	#additional packages that may be useful
	[extras]
	name=CentOS-$releasever - Extras - 163.com
	#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
	baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
	gpgcheck=1
	gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

	#additional packages that extend functionality of existing packages
	[centosplus]
	name=CentOS-$releasever - Plus - 163.com
	baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
	gpgcheck=1
	enabled=0
	gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

其中[base]baseurl的$releasever是指Linux版本,$basearch是平臺

[root@localhost yum.repos.d]# yum install -y wget
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	Resolving Dependencies
	--> Running transaction check
	---> Package wget.x86_64 0:1.14-15.el7_4.1 will be installed
	--> Finished Dependency Resolution

	Dependencies Resolved

	==================================================================================================
	 Package           Arch                Version                         Repository            Size
	==================================================================================================
	Installing:
	 wget              x86_64              1.14-15.el7_4.1                 updates              547 k

	Transaction Summary
	==================================================================================================
	Install  1 Package

	Total download size: 547 k
	Installed size: 2.0 M
	Downloading packages:
	wget-1.14-15.el7_4.1.x86_64.rpm                                            | 547 kB  00:00:00     
	Running transaction check
	Running transaction test
	Transaction test succeeded
	Running transaction
	  Installing : wget-1.14-15.el7_4.1.x86_64                                                    1/1 
	  Verifying  : wget-1.14-15.el7_4.1.x86_64                                                    1/1 

	Installed:
	  wget.x86_64 0:1.14-15.el7_4.1                                                                   

	Complete!

yum下載rpm包方

安裝擴展源epel

  • yum install -y epel-release
  • yum list | grep epel
[root@localhost ~]# cd /etc/yum.repos.d
[root@localhost ~]# ls
	CentOS7-Base-163.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-Vault.repo
	[root@localhost yum.repos.d]# yum install -y epel-release
	Loaded plugins: fastestmirror
	base                                                                       | 3.6 kB  00:00:00     
	extras                                                                     | 3.4 kB  00:00:00     
	updates                                                                    | 3.4 kB  00:00:00     
	Loading mirror speeds from cached hostfile
	Resolving Dependencies
	--> Running transaction check
	---> Package epel-release.noarch 0:7-9 will be installed
	--> Finished Dependency Resolution

	Dependencies Resolved

	==================================================================================================
	 Package                     Arch                  Version            Repository             Size
	==================================================================================================
	Installing:
	 epel-release                noarch                7-9                extras                 14 k

	Transaction Summary
	==================================================================================================
	Install  1 Package

	Total download size: 14 k
	Installed size: 24 k
	Downloading packages:
	epel-release-7-9.noarch.rpm                                                |  14 kB  00:00:05     
	Running transaction check
	Running transaction test
	Transaction test succeeded
	Running transaction
	  Installing : epel-release-7-9.noarch                                                        1/1 
	  Verifying  : epel-release-7-9.noarch                                                        1/1 

	Installed:
	  epel-release.noarch 0:7-9                                                                       

	Complete!
[root@localhost ~]# ls
	CentOS7-Base-163.repo  CentOS-Sources.repo  epel.repo
	CentOS-Debuginfo.repo  CentOS-Vault.repo    epel-testing.repo
[root@localhost ~]# vi epel.repo
	[epel]
	name=Extra Packages for Enterprise Linux 7 - $basearch
	#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
	mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
	failovermethod=priority
	enabled=1
	gpgcheck=1
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

	[epel-debuginfo]
	name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
	#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch/debug
	mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
	failovermethod=priority
	enabled=0
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
	gpgcheck=1

	[epel-source]
	name=Extra Packages for Enterprise Linux 7 - $basearch - Source
	#baseurl=http://download.fedoraproject.org/pub/epel/7/SRPMS
	mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
	failovermethod=priority
	enabled=0
	gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
	gpgcheck=1

yum下載rpm包方式

  1. yum install -y 包名 --downloadonly #只下載rpm包但不安裝
[root@localhost ~]# yum install zsh --downloadonly
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	 * epel: mirrors.ustc.edu.cn
	Resolving Dependencies
	--> Running transaction check
	---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
	--> Finished Dependency Resolution

	Dependencies Resolved

	==================================================================================================
	 Package            Arch                  Version                       Repository           Size
	==================================================================================================
	Installing:
	 zsh                x86_64                5.0.2-28.el7                  base                2.4 M

	Transaction Summary
	==================================================================================================
	Install  1 Package

	Total download size: 2.4 M
	Installed size: 5.6 M
	Background downloading packages, then exiting:
	zsh-5.0.2-28.el7.x86_64.rpm                                                | 2.4 MB  00:00:03     
	exiting because "Download Only" specified
[root@localhost ~]# rpm -q zsh
	package zsh is not installed
  1. ls /var/cache/yum/x86_64/7/ #查找默認下載位置
[root@localhost ~]# ls /var/cache/yum/x86_64/7/base/packages/
	zsh-5.0.2-28.el7.x86_64.rpm

經過Repository的倉庫名找路徑

  1. yum install -y 包名 --downloadonly --downloaddir=路徑 #指定下載路徑
[root@localhost ~]# yum install zsh --downloadonly --downloaddir=/root/
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	 * epel: mirror.ehost.vn
	Resolving Dependencies
	--> Running transaction check
	---> Package zsh.x86_64 0:5.0.2-28.el7 will be installed
	--> Finished Dependency Resolution

	Dependencies Resolved

	==================================================================================================
	 Package            Arch                  Version                       Repository           Size
	==================================================================================================
	Installing:
	 zsh                x86_64                5.0.2-28.el7                  base                2.4 M

	Transaction Summary
	==================================================================================================
	Install  1 Package

	Total download size: 2.4 M
	Installed size: 5.6 M
	Background downloading packages, then exiting:
	exiting because "Download Only" specified

[root@localhost ~]# ls
	anaconda-ks.cfg  zsh-5.0.2-28.el7.x86_64.rpm
  1. yum reinstall -y 包名 --downloadonly --downloaddir=路徑 #從新下載包
[root@localhost ~]# yum install vim-enhanced --downloadonly --downloaddir=/root/
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	 * epel: ftp.cuhk.edu.hk
	Package 2:vim-enhanced-7.4.160-2.el7.x86_64 already installed and latest version
	Nothing to do

當系統已安裝了rpm包,再次下載rpm則不會成功,這時候使用reinstall從新安裝則能夠成功下載rpm包

[root@localhost ~]# yum reinstall vim-enhanced --downloadonly --downloaddir=/root/
	Loaded plugins: fastestmirror
	Loading mirror speeds from cached hostfile
	 * epel: ftp.cuhk.edu.hk
	Resolving Dependencies
	--> Running transaction check
	---> Package vim-enhanced.x86_64 2:7.4.160-2.el7 will be reinstalled
	--> Finished Dependency Resolution

	Dependencies Resolved

	==================================================================================================
	 Package                  Arch               Version                       Repository        Size
	==================================================================================================
	Reinstalling:
	 vim-enhanced             x86_64             2:7.4.160-2.el7               base             1.0 M

	Transaction Summary
	==================================================================================================
	Reinstall  1 Package

	Total download size: 1.0 M
	Installed size: 2.2 M
	Background downloading packages, then exiting:
	vim-enhanced-7.4.160-2.el7.x86_64.rpm                                      | 1.0 MB  00:00:01     
	exiting because "Download Only" specified
[root@localhost ~]# ls 
	anaconda-ks.cfg  vim-enhanced-7.4.160-2.el7.x86_64.rpm  zsh-5.0.2-28.el7.x86_64.rpm
相關文章
相關標籤/搜索