Update a Single Package Using APT
When managing Debian or Ubuntu systems, one of the most common tasks you might encounter as a system administrator is updating software packages. While apt-get upgrade
is a popular command to upgrade all packages on your system, sometimes you need to update only a single package. This article will guide you through the process of updating a single package using APT, explain the command involved, and discuss some related commands that are useful in similar contexts.
Understanding APT
APT (Advanced Package Tool) is the default package manager for Debian and its derivatives like Ubuntu. It simplifies the process of managing software by automating the retrieval, configuration, and installation of software packages.
Updating a Single Package
To update a specific package, you should use the apt-get install
command followed by the package name with the --only-upgrade
flag. This command tells APT to upgrade the specified package without considering upgrades for other packages. Here’s how you can do it:
sudo apt-get install --only-upgrade <package-name>
Replace <package-name>
with the name of the package you want to update. For example, to update only the nginx
package, you would use:
sudo apt-get install --only-upgrade nginx
Why Not apt-get upgrade
?
The apt-get upgrade
command upgrades all upgradable packages on your system. It does not allow you to specify a package to upgrade, which is why it’s not suitable when you want to update just one package or a specific list of packages.
Checking for Available Updates
Before you decide to update a package, you might want to check if there are updates available. You can do this using the apt list --upgradable
command, which lists all packages for which updates are available:
apt list --upgradable
If you want to check if there’s an update available for a specific package, you can filter the output using grep
:
apt list --upgradable | grep <package-name>
Holding and Unholding Packages
Sometimes, you might not want a package to be updated when using general update commands. APT allows you to hold packages at their current version. To hold a package, use:
sudo apt-mark hold <package-name>
And to unhold it:
sudo apt-mark unhold <package-name>
Automating Updates
For system administrators, automating updates can save a lot of time and effort. You can automate the update of specific packages using a cron job. Here’s a simple example of a cron job that updates the nginx
package every day at midnight:
0 0 * * * sudo apt-get install --only-upgrade nginx
Make sure to edit your crontab with care:
sudo crontab -e
Conclusion
Understanding how to update specific packages is crucial for maintaining the security and stability of your system without applying broad updates that might disrupt services. The apt-get install --only-upgrade
command is a powerful tool in a system administrator’s arsenal, allowing precise control over package updates.