Debian upgrade or update a single package using apt-get

last updated in Categories , ,

I am a new Debian Linux server sysadmin. I need to upgrade or update a single package using apt-get command or apt command. How do I update a specific package in Debian Linux server hosted in the cloud data center? How do I upgrade a single package using apt-get?

Introduction: By default when you run either ‘apt-get upgrade’ or ‘apt upgrade’, Debian Linux will update all installed packages. However, in some cases, you may want to upgrade a specific package only such as Apache or Nginx on a Debian Linux. It is also possible to blacklist upgrading packages on Debian Linux. As a Debian Linux sysadmin, you have full control over package management.

How to Debian upgrade or update a single package

The procedure to update a a specific package on Debian:

  1. Open the Terminal application by visiting menus in the GUI
  2. Update package index by running sudo apt update command
  3. Now only update nginx package by running sudo apt install nginx command.
  4. If nginx 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 nginx

Let us see all commands in details for Debian Linux 6.x/7.x/8.x/9.x server.

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
Sample outputs:

Ign:1 http://deb.debian.org/debian stretch InRelease                                    
Get:2 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]    
Get:3 http://deb.debian.org/debian stretch-updates InRelease [91.0 kB]
Get:4 http://deb.debian.org/debian stretch Release [118 kB]      
Get:5 http://security.debian.org/debian-security stretch/updates/main Sources [181 kB]
Get:6 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [452 kB]
Get:7 http://security.debian.org/debian-security stretch/updates/main Translation-en [195 kB]
Get:8 http://deb.debian.org/debian stretch Release.gpg [2,434 B]                  
Get:9 http://deb.debian.org/debian stretch-updates/main Sources.diff/Index [5,656 B]
Get:10 http://deb.debian.org/debian stretch-updates/main amd64 Packages.diff/Index [5,656 B]
Get:11 http://deb.debian.org/debian stretch-updates/main Translation-en.diff/Index [3,688 B]
Get:12 http://deb.debian.org/debian stretch-updates/main Sources 2018-07-20-2027.50.pdiff [777 B]
Get:13 http://deb.debian.org/debian stretch-updates/main Sources 2018-07-31-2010.17.pdiff [385 B]
Get:14 http://deb.debian.org/debian stretch-updates/main Sources 2018-10-20-2016.48.pdiff [792 B]
Get:14 http://deb.debian.org/debian stretch-updates/main Sources 2018-10-20-2016.48.pdiff [792 B]
Get:15 http://deb.debian.org/debian stretch-updates/main amd64 Packages 2018-07-20-2027.50.pdiff [1,134 B]
Get:16 http://deb.debian.org/debian stretch-updates/main amd64 Packages 2018-07-31-2010.17.pdiff [1,388 B]
Get:17 http://deb.debian.org/debian stretch-updates/main amd64 Packages 2018-10-20-2016.48.pdiff [1,577 B]
Get:17 http://deb.debian.org/debian stretch-updates/main amd64 Packages 2018-10-20-2016.48.pdiff [1,577 B]
Get:18 http://deb.debian.org/debian stretch-updates/main Translation-en 2018-07-20-2027.50.pdiff [1,311 B]
Get:19 http://deb.debian.org/debian stretch-updates/main Translation-en 2018-07-31-2010.17.pdiff [36 B]
Get:19 http://deb.debian.org/debian stretch-updates/main Translation-en 2018-07-31-2010.17.pdiff [36 B]
Get:20 http://deb.debian.org/debian stretch/main Sources [6,758 kB]
Get:21 http://deb.debian.org/debian stretch/main amd64 Packages [7,099 kB]
Get:22 http://deb.debian.org/debian stretch/main Translation-en [5,393 kB]                                                                                                                                        
Fetched 20.4 MB in 8s (2,448 kB/s)                                                                                                                                                                                
Reading package lists... Done
Building dependency tree       
Reading state information... Done
40 packages can be upgraded. Run 'apt list --upgradable' to see them.

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 apache2 web server:
$ sudo apt-get install apache2
If apache2 package is already installed it will try to update to latest version:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
apache2 is already the newest version (2.4.25-3+deb9u5).
0 upgraded, 0 newly installed, 0 to remove and 40 not upgraded.

However, the following will not install a new nginx package if not installed:
$ sudo apt-get --only-upgrade install apache2
In this following example, apache2 is installed and I am requesting update. However, nginx package not installed on a Debian and I am still requesting an update for it:
$ sudo apt-get install apache2
$ sudo apt-get --only-upgrade install nginx

Debian upgrade or update a single package using apt-get

Conclusion

You learned how to update a specific package on Debian Linux based system or server. 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.

Start the discussion at www.nixcraft.com

Historical Comment Archive

1 comment

    Have a question? Post it on our forum!