Methods of locking and unlocking software package versions in CentOS and RedHat (details of using Yum versionlock)

Time:2021-7-20

So how to lock a package in a specific version? Now let me introduce a method. Use the yum versionlock command to lock the version.

1. Installation

Copy code

The code is as follows:

# yum install yum-plugin-versionlock.noarch

2. Add lock package

Example: Lock Perl package to current version

Copy code

The code is as follows:

# yum versionlock perl
Loaded plugins: fastestmirror, versionlock
Adding versionlock on: 4:perl-5.10.1-127.el6
versionlock added: 1

3. View lock list

Copy code

The code is as follows:

# yum versionlock list
Loaded plugins: fastestmirror, versionlock
4:perl-5.10.1-127.el6.*
versionlock list done

4. Clear single packet lock

Copy code

The code is as follows:

# yum versionlock delete ‘4:perl-5.10.1-127.el6.*’
Loaded plugins: fastestmirror, versionlock
Deleting versionlock for: 4:perl-5.10.1-127.el6.*
versionlock deleted: 1

5. Clear all locks

Copy code

The code is as follows:

# yum versionlock clear
Loaded plugins: fastestmirror, versionlock
versionlock cleared

6. Examples

Copy code

The code is as follows:

# yum check-update perl
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* epel: mirror01.idc.hinet.net
* extras: mirrors.163.com
* updates: mirrors.163.com

perl.x86_64 4:5.10.1-136.el6 base

Lock the current version of Perl

Copy code

The code is as follows:

# yum versionlock perl
Loaded plugins: fastestmirror, versionlock
Adding versionlock on: 4:perl-5.10.1-127.el6
versionlock added: 1

Update Perl version

Copy code

The code is as follows:

# yum update perl
Loaded plugins: fastestmirror, versionlock
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* epel: mirror01.idc.hinet.net
* extras: mirrors.163.com
* updates: mirrors.163.com
Setting up Update Process
No Packages marked for Update

No packages marked for update is successful.

To update, unlock Perl

Copy code

The code is as follows:

# yum versionlock delete ‘4:perl-5.10.1-127.el6.*’
Loaded plugins: fastestmirror, versionlock
Deleting versionlock for: 4:perl-5.10.1-127.el6.*
versionlock deleted: 1
# yum versionlock list
Loaded plugins: fastestmirror, versionlock
0:mysql-server-5.1.73-3.el6_5.*
0:mysql-5.1.73-3.el6_5.*
versionlock list done

Update Perl package

Copy code

The code is as follows:

# yum update -y perl
Updated:
perl.x86_64 4:5.10.1-136.el6
Complete!

Perl version before and after update

Copy code

The code is as follows:

[[email protected] ~]
# rpm -qa | grep perl
perl-5.10.1-127.el6.x86_64
[[email protected] ~]
# rpm -qa | grep perl
perl-5.10.1-136.el6.x86_64

Using this instruction can avoid upgrading the software package to the latest version by mistake. Especially in the production environment, some configuration parameters may be incompatible with the update of the software package, which will affect the normal access.