Skip to content Skip to main navigation Skip to footer

CentOS:yum更新时如何限制某个包为特定的版本

在centos下,当我们使用yum udpate命令更新系统的软件包的时候,会默认将所以需要更新的包都显示出来,并更新。那么如果你想让某一个包一直保持在某一个版本,该如何来做呢?你可以通过下面的两个方法来实现:
1.执行yum update 命令的时候,使用”–exclude” 选项,来排除不需要更新的软件包。
2. 使用yum versionlock 工具
linux操作系统

方法一:使用yum –exclude 命令来限定不更新的软件包

1.编辑配置文件“/etc/yum.conf”
2. 加入下面的内容到配置文件里:

exclude=http* ===》(在这里加入不需要更新的软件包)
 

保存并退出。

方法二:通过yum versionlock工具限制软件包更新

首先你需要安装”yum-plugin-versionlock”工具,并传入需要排除的软件包的名字。这样就可以保护某些软件包的版本不需要更新。
centos 下安装yum-plugin-versionlock
输入下面的命令来安装yum-plugin-versionlock

yum -y install yum-versionlock
或
yum -y install yum-plugin-versionlock
 

命令输出:

[root@devops Desktop]# yum -y install yum-versionlock
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.btte.net
 * updates: mirrors.btte.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package yum-plugin-versionlock.noarch 0:1.1.30-30.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package                      Arch         Version             Repository  Size
================================================================================
Installing:
 yum-plugin-versionlock       noarch       1.1.30-30.el6       base        30 k
Transaction Summary
================================================================================
Install       1 Package(s)
Total download size: 30 k
Installed size: 43 k
Downloading Packages:
yum-plugin-versionlock-1.1.30-30.el6.noarch.rpm          |  30 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : yum-plugin-versionlock-1.1.30-30.el6.noarch                  1/1
  Verifying  : yum-plugin-versionlock-1.1.30-30.el6.noarch                  1/1
Installed:
  yum-plugin-versionlock.noarch 0:1.1.30-30.el6
Complete!
 

举个例子:使用versionlock工具限定httpd工具不更新

yum versionlock httpd
或者
yum versionlock add httpd
 

命令输出:

[root@devops Desktop]# yum versionlock httpd
Loaded plugins: fastestmirror, refresh-packagekit, security, versionlock
Adding versionlock on: 0:httpd-2.2.15-15.el6.centos.1
versionlock added: 1
 

如果想删除某个软件包部在限制更新之列,可以使用“delete”选项,如下面的命令:

yum versionlock delete httpd
 

列出当前限定列表里的所有软件包
输入下面的命令:

yum versionlock list
 

命令输出:

[root@devops Desktop]# yum versionlock  list
Loaded plugins: fastestmirror, refresh-packagekit, security, versionlock
0:wget-1.12-1.4.el6.*
0:httpd-2.2.15-15.el6.centos.1.*
versionlock list done
 

移除所有的限定软件包列表
输入下面的命令:

yum versionlock clear
 

命令输出:

[root@devops Desktop]# yum versionlock clear
Loaded plugins: fastestmirror, refresh-packagekit, security, versionlock
versionlock cleared
 
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.