I am a new Ubuntu Linux server system administrator. I need to upgrade or update a single package using apt-get command or apt command. How do I update a specific package in Ubuntu Linux? How do I upgrade a single package using apt-get?
Introduction: By default when you run either ‘apt-get upgrade’ or ‘apt upgrade’, Ubuntu will update all installed packages. However, in some cases, you may want to upgrade a specific package only such as Apache or Nginx. It is also possible to blacklist upgrading packages on Ubuntu Linux. As an Ubuntu Linux system administrator, you have full control over package management.
How to Ubuntu upgrade or update a single package
The procedure to update a a specific package on Ubuntu:
- Open the Terminal application
- Fetch package index by running sudo apt update command
- Now only update apache2 package by running sudo apt install apache2 command.
- If apache2 package already installed it will try to update to the latest version. If you do not want to install new packages; when used in conjunction with install, only-upgrade will install upgrades for already installed packages only and ignore requests to install new packages. Try sudo apt --only-upgrade install apache2
Let us see command in details.
How to upgrade a single package using apt-get?
As usual you need to fetch an updated index from the Internet:$ sudo apt-get update
You need to use following format with the apt-get command:$ sudo apt-get --only-upgrade install Package
$ sudo apt-get install Package
Let us try to upgrade nginx web server:$ sudo apt-get install nginx
If nginx package is already installed it will try to update to latest version:
Reading package lists... Done Building dependency tree Reading state information... Done nginx is already the newest version (1.10.3-0ubuntu0.16.04.2). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
However, the following will not install a new nginx package if not installed:$ sudo apt-get --only-upgrade install nginx
In this following example, htop is installed and I am requesting update. However, atop not installed and I am still requesting an update for it:$ sudo apt-get install htop
$ sudo apt-get --only-upgrade install atop
Conclusion
You learned how to update a specific package on Ubuntu Linux. Please note that you need to pass the --only-upgrade to the apt command when you only want that single package upgrade provided that it is installed. See apt man page here for more info.