Ubuntu upgrade or update a single package using apt-get

last updated in Categories , ,

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:

  1. Open the Terminal application
  2. Fetch package index by running sudo apt update command
  3. Now only update apache2 package by running sudo apt install apache2 command.
  4. 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 all commands and examples 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/apt 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

Ubuntu upgrade or update a single package using apt-get


First, download package information from all configured source:
$ sudo apt-get update
Run the to see availble updates:
$ sudo apt list --upgradable

Listing... Done
apport-gtk/focal-security,focal-security 2.20.11-0ubuntu27.6 all [upgradable from: 2.20.11-0ubuntu27.4]
apport/focal-security,focal-security 2.20.11-0ubuntu27.6 all [upgradable from: 2.20.11-0ubuntu27.4]
libssh-4/focal-updates,focal-security 0.9.3-2ubuntu2.1 amd64 [upgradable from: 0.9.3-2ubuntu2]
libssh-gcrypt-4/focal-updates,focal-security 0.9.3-2ubuntu2.1 amd64 [upgradable from: 0.9.3-2ubuntu2]
libwhoopsie0/focal-security 0.2.69ubuntu0.1 amd64 [upgradable from: 0.2.69]
ppp/focal-security 2.4.7-2+4.1ubuntu5.1 amd64 [upgradable from: 2.4.7-2+4.1ubuntu5]
python3-apport/focal-security,focal-security 2.20.11-0ubuntu27.6 all [upgradable from: 2.20.11-0ubuntu27.4]
python3-problem-report/focal-security,focal-security 2.20.11-0ubuntu27.6 all [upgradable from: 2.20.11-0ubuntu27.4]
whoopsie/focal-security 0.2.69ubuntu0.1 amd64 [upgradable from: 0.2.69]

We have 9 updates available but we are just going to update ppp package:
$ sudo apt-get --only-upgrade install ppp
## OR ##
$ sudo apt --only-upgrade install ppp

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be upgraded:
1 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Need to get 328 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://security.ubuntu.com/ubuntu focal-security/main amd64 ppp amd64 2.4.7-2+4.1ubuntu5.1 [328 kB]
Fetched 199 kB in 2s (123 kB/s)
(Reading database ... 288234 files and directories currently installed.)
Preparing to unpack .../ppp_2.4.7-2+4.1ubuntu5.1_amd64.deb ...
Unpacking ppp (2.4.7-2+4.1ubuntu5.1) over (2.4.7-2+4.1ubuntu5) ...
Setting up ppp (2.4.7-2+4.1ubuntu5.1) ...
Processing triggers for systemd (245.4-4ubuntu3.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for libc-bin (2.31-0ubuntu9) ...


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/apt-get man page online here for more information or type the following man command:
$ man apt
$ man apt-get

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.


1 comment

  1. To upgrade a single package using apt-get and apt command:
    # apt update
    # apt --only-upgrade install pkg1
    # apt-get --only-upgrade bash

Leave a Comment