How to Lock Package Version & Prevent from Being Updated in Ubuntu / Debian

This is a beginner’s guide shows how to lock a software version in Ubuntu / Debian / Linux Mint. So the installed package will always be the locked version even if a higher release is available.

Linux users sometimes prefer a software in certain package version, and don’t want to update it. So the feature “Lock Version” is available, and here’s how to do it in apt based systems.

Lock package version via a graphical tool:

For the desktop systems, firstly open your system package manager, search for and install Synaptic Package Manager.

Or open terminal and run the command to install the tool:

sudo apt install synaptic

Once installed, launch Synaptic and search the package you want to lock version (nginx for instance).

Then select the package or packages (press and hold the Ctrl key), and go to menu “Package -> Lock Version“.

Finally, the locked packages will have wine red as background color, with little lock icon at the beginning.

That’s it.

Lock package version in Ubuntu / Debian Server:

For server edition without desktop UI, you can create a config file under /etc/apt/preferences.d to handle it.

Firstly login to the Ubuntu / Debian server, run command to check out the package details (nginx for instance):

apt-cache policy nginx

In the output, write down the package version you want to keep.

Then create (and edit) a config file by running command:

sudo nano /etc/apt/preferences.d/99my_custom_package

And write following lines:

# Lock nginx package version to 1.18.1-0ubuntu1 (description line which is optional).
Package: nginx
Pin: version 1.18.1-0ubuntu1
Pin-Priority: 1001

Save the file by pressing Ctrl+X, type y, and finally hit Enter.

You can also do for the dependency packages (e.g., nginx-core, nginx-common, and more) by adding following lines. Each section contains 3 lines, and separated by a blank line.

Package: nginx-core
Pin: version 1.18.1-0ubuntu1
Pin-Priority: 1001

Package: nginx-common
Pin: version 1.18.1-0ubuntu1
Pin-Priority: 1001

Do change the version number if the package has a different one.

Finally run sudo apt update to refresh package cache and done!

Merilyn Ne
Hi, I'm Merilyn Ne, a computer geek working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.