How to Upgrade a Single Package in Ubuntu

On Ubuntu to install newer versions of the packages we run apt-get update followed by apt-get upgrade commands. This will update all installed packages which have new versions available in the repositories.

In some situation we have to upgrade only a single package such as PHP, Apache or Nginx.

Upgrade a single package in Ubuntu

To upgrade a specific package run sudo apt install package-name.

First get the updated package list, but it does not install or update the package:

$ sudo apt update

The following command will update the package gimp if its already installed:

$ sudo apt install gimp
Output
Reading package lists… Done
 Building dependency tree
 Reading state information… Done
 gimp is already the newest version (2.10.18-1).
 0 upgraded, 0 newly installed, 0 to remove and 101 not upgraded.

Note: You can use the same command for a fresh package installation and also updating to a newer version.

Upgrade a specific package using --only-upgrade

To upgrade single or specific package use --only-upgrade option. Here the difference from the above method is that it will not update if the package not already installed.

The following command upgrade the gimp package:

$ sudo apt-get --only-upgrade install gimp
Output
Reading package lists… Done
 Building dependency tree
 Reading state information… Done
 gimp is already the newest version (2.10.18-1).
 0 upgraded, 0 newly installed, 0 to remove and 101 not upgraded.

Lets see, how the output look like if the package not present:

$ sudo apt-get --only-upgrade install krita

From the output you can see that its skipping the upgrade because krita package is not installed.

Reading package lists… Done
 Building dependency tree
 Reading state information… Done
 Skipping krita, it is not installed and only upgrades are requested.
 0 upgraded, 0 newly installed, 0 to remove and 101 not upgraded.

Conclusion

In this tutorial, we learned how to upgrade a single package on Ubuntu. It is also possible to exclude specific package from apt-get upgrade.

For more information visit apt/apt-get man page. Thanks for reading and please leave your comments.

Leave a Comment