This quick tutorial will show you how to update packages on your Ubuntu server via the command line. There are only a few commands needed to finish the job.
Before making any updates on your server, especially when processing updates for vital packages throughout your system, it's always a good idea to create a backup or snapshot of your server first. Should anything go wrong during the upgrade process that you can't easily roll back, you'll have a backup that you can use to restore if needed.
You'll also need to make sure you have administrative access to the server. If you don't, you won't be able to run these updates and you'll need to contact someone who has access.
Update Ubuntu Packages
When updating packages on a Ubuntu server, you're instructing the server to fetch all pending package lists from the repositories and update the index files on your machine. This doesn't actually upgrade your applications yet, so we'll cover that shortly:
$ sudo apt update
Upgrade Ubuntu Packages
Now that the index files are updated on your server, you'll need to upgrade all packages and their dependencies by fetching them from their respective repositories. This command only upgrades the existing packages to the latest versions. It does not remove the obsolete package versions:
$ sudo apt upgrade
Update & Remove Obsolete Packages
If you're looking to upgrade your packages and their dependencies to their latest versions and remove any existing obsolete packages in one shot, this command will do the trick:
$ sudo apt dist-upgrade
Processing Security Updates
If you're only looking to install the latest security updates on your Ubuntu server, you can do so while bypassing all other non-security packages with this command:
$ sudo apt install unattended-upgrades
This command will run through the upgrade process silently, installing updates without user consent or interaction.
If you'd rather run the interactive process that steps through each of the updates individually, just add the
-d switch to the end of the command:
$ sudo apt install unattended-upgrades -d
Reboot Your Server
Once all of your packages and security updates have been updated and installed in Ubuntu, make sure to reboot your server for all updates to take effect.
Once the reboot has been completed, do a once-over through your running applications to ensure everything is updated correctly without error.
As a rule of thumb, it's a good idea to retain your backups for at least a few months to ensure you still have access to certain restore points if needed.
In this tutorial, you learned how to update packcages on a Ubuntu server. Ubuntu makes it easy to update and install the latest package and application versions. We also covered installing security updates independently from any other upgrades. All you need are the few commands we covered above and administrative access to the server.