Ubuntu upgrade or update a single package using apt-get

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.

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 updateYou need to use following format with the apt-get command:$ sudo apt-get --only-upgrade install Package$ sudo apt-get install PackageLet us try to upgrade nginx web server:$ sudo apt-get install nginxIf nginx package is already installed it will try to update to latest version:

1

2

3

4

5

Reading packagelists...Done

Building dependency tree

Reading state information...Done

nginx isalready the newest version(1.10.3-0ubuntu0.16.04.2).

0upgraded,0newly installed,0toremove and0notupgraded.

However, the following will not install a new nginx package if not installed:$ sudo apt-get --only-upgrade install nginxIn 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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.