Showing posts with label dpkg. Show all posts
Showing posts with label dpkg. Show all posts

Friday, June 6, 2014

How to prevent a package from upgrading in Debian

Often times, when you are having a server with a package installed, example database package and you want the rest of the packages in the system upgraded but not the database package. How can you do it?

With Debian, you can! You can set a package not to upgrade by setting flag to the package with dpkg. The followings are parameters that you need to be use.
--get-selections [package-name-pattern...]
Get list of package selections, and write it to stdout. Without a pattern, non-installed packages (i.e. those which have been previously
purged) will not be shown.

--set-selections
Set package selections using file read from stdin. This file should be in the format 'package state', where state is one of install, hold,
deinstall or purge. Blank lines and comment lines beginning with '#' are also permitted.

The available file needs to be up-to-date for this command to be useful, otherwise unknown packages will be ignored with a warning. See the
--update-avail and --merge-avail commands for more information.

Let's check what is the state of a current package. To narrate better, I will use mongodb.
jason@localhost:~$ dpkg --get-selections mongodb-org
mongodb-org install

If you decided to stop this package from the next upgrade, you should set flag hold to this package.
jason@localhost:~$ echo "mongodb-org hold" | sudo dpkg --set-selections
jason@localhost:~$ $ dpkg --get-selections mongodb-org
mongodb-org hold

Notice that the package state has transitioned into hold. Okay, let's say we want the package to be upgrade in the next upgrade, then we can set install flag to this package.
jason@localhost:~$ echo "mongodb-org install" | sudo dpkg --set-selections
jason@localhost:~$ dpkg --get-selections mongodb-org
mongodb-org install

So, that's it, simple and quick.