Skip to Content

How to Update Packages in Ubuntu via Command Line

This quick tutorial will show you how to update packages in Ubuntu via the command line. There are only a few commands needed to finish the job.

Preliminary Steps

Create A Backup

Before making any updates on your server, especially when processing updates for vital packages, it's always a good idea to first create a backup or snapshot of your server. 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.

Check Your Access

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 yourself and will need to contact someone who has access.

Update Packages in Ubuntu

When updating packages in Ubuntu, you're instructing the server to fetch all pending package lists from the available repositories and update the index files on your machine:

$ sudo apt update

Upgrade Packages in Ubuntu

Now that the index files are updated, you'll need to upgrade the packages and their dependencies. This command upgrades the existing packages to their 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

Process 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 packages in Ubuntu and install security updates independently from all other updates.

Last Updated: January 27, 2023
Created: June 02, 2022

Comments

Kartik Patel

2y
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

2y
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.