1. Introduction

Typically, package managers can upgrade the Linux packages on the system. While the apt-get upgrade command updates all the packages currently installed, there are scenarios where upgrading a single package is necessary.

In this tutorial, we’ll discuss the various methods for upgrading individual Linux packages within the repository.

2. Methods for Upgrading a Single Package

Generally, there are multiple ways to upgrade packages in Linux systems. Now, let’s focus on the two most common methods that system administrators use to upgrade a single package.

First, let’s use the dpkg command to provide package details for the Nginx web server, including package versions on the system. This helps us distinguish between the current and latest versions:

$ dpkg -l | grep "nginx"
ii  nginx-core                                 1.14.0-0ubuntu1.8                             amd64        nginx web/proxy server (standard version)

For instance, the nginx version available in the system is 1.14.0-0ubuntu1.8.

2.1. Using the –only-upgrade Option

Next, we use the –only-upgrade option with apt-get install to instruct the package manager to exclusively upgrade specified packages without installing any new packages. This ensures updating only the specific packages to their latest versions.

The apt-get install –only-upgrade nginx -y command is used to exclusively upgrade the nginx package, only if it’s already installed:

$ sudo apt-get install --only-upgrade nginx -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be upgraded:
  nginx
1 upgraded, 0 newly installed, 0 to remove, and 0 not upgraded.
Need to get 2,376 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 nginx amd64 1.14.0-0ubuntu1.9 [2,376 kB]
Fetched 2,376 kB in 2s (1,467 kB/s)
(Reading database ... 223876 files and directories currently installed.)
Preparing to unpack .../nginx_1.14.0-0ubuntu1.9_amd64.deb ...
Unpacking nginx (1.14.0-0ubuntu1.9) over (1.14.0-0ubuntu1.8) ...
Setting up nginx (1.14.0-0ubuntu1.9) ...
...

Notably, the 1 upgraded, 0 newly installed … message indicates the upgrade of one package without installing any new packages. In fact, this approach helps maintain the system configurations intact without introducing any additional changes.

2.2. Using apt-get install

Alternatively, we can also use apt-get install to upgrade existing system packages. When used without the –only-upgrade option, this command can install new packages or upgrade already installed packages to their latest versions if updates are available:

$ sudo apt-get install tcpdump -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be upgraded:
  tcpdump
1 upgraded, 0 newly installed, 0 to remove and 125 not upgraded.
Need to get 501 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu jammy-updates/main amd64 tcpdump amd64 4.99.1-3ubuntu0.2 [501 kB]
Fetched 501 kB in 1s (395 kB/s)
(Reading database ... 282558 files and directories currently installed.)
Preparing to unpack .../tcpdump_4.99.1-3ubuntu0.2_amd64.deb ...
Unpacking tcpdump (4.99.1-3ubuntu0.2) over (4.99.1-3ubuntu0.1) ...
Setting up tcpdump (4.99.1-3ubuntu0.2) ...
Installing new version of config file /etc/apparmor.d/usr.bin.tcpdump ...
Processing triggers for man-db (2.10.2-1) ...
...

In this case, the output indicates that only one package, tcpdump, will receive an upgrade. Lastly, it also states that there are no new packages to be installed, no packages to be removed, and 125 packages that have updates available but aren’t being upgraded at this time.

Here, we’ve successfully upgraded the tcpdump package to its latest 4.99.1 version.

3. Conclusion

Understanding how to upgrade individual packages in a Linux system is crucial for maintaining system integrity and security. By utilizing a package manager via the apt-get command, administrators can manage software updates efficiently. This approach ensures that systems remain up-to-date with the latest features and security patches, contributing to their overall stability and reliability.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments