Skip to Content

How to Update Packages in Ubuntu via Command Line

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.

Preliminary Steps

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.

Conclusion

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.

Created: June 02, 2022

Comments

Kartik Patel

2mo
New release '20.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
2 updates could not be installed automatically. For more details,
see /var/log/unattended-upgrades/unattended-upgrades.log
-- my issue is how to install new version. it is asking me to install 1st 2 updates which is not done then go ahead but i do not know how to perform that to install 2 updates which is not done.. any help ?

Reply
 

Josh Rowe

2mo
Make sure you have all unsaved work saved, then reboot the server. Once the server is fully rebooted, try running the command again.

Reply

Add A Comment

Comment Etiquette: Wrap code in a <code> and </code>. Please keep comments on-topic, do not post spam, keep the conversation constructive, and be nice to each other.