Want to update packages on Ubuntu and have no idea how to do it?
To update all the upgradeable deb packages at once, you can use this combination of two commands:
sudo apt update && sudo apt upgrade -y
Want more details? Well, this guide will cover every aspect of how you can update packages on Ubuntu, which includes:
- Updating the deb packages using apt
- Updating the snap packages
So let's start with the first one.
How to update deb packages using apt on Ubuntu
If you don't know, Ubuntu is based on Debian, which uses the apt package manager to install, manage, and remove deb packages.
So there are 3 steps that you need to follow:
- Update system repository
- List the outdated packages
- Update one or multiple packages using the apt package manager
Let's start with the step 1.
Step 1: Update the system repository
Updating the system repository will update the repository index and fetch information about the latest packages available for your system.
To update the system repository, all you have to do is execute the simple command:
sudo apt update
If an update is available for any package, it will show you the number of outdated packages and in my case, there are 32 outdated packages.
Step 2: List outdated packages
Once you update repositories and if it shows the number of outdated packages, you may want to list them if you only want to update the selective packages.
To list outdated packages, use the following command:
apt list --upgradable
Step 3: Update packages
This section is further divided into 2 parts:
- Update single package
- Update all the packages at once
So let's start with updating the single package.
Update single package using apt
If you want to update only one package, then, you can use the apt in the following syntax:
sudo apt install --only-upgrade package-name
For example, if I want to update
ufw, then, I will be using the following:
sudo apt install --only-upgrade ufw
Update all the packages at once
If you wish to upgrade all the packages at once, then you can use the following command:
sudo apt upgrade
Y and it will start installing the listed packages.
How to update snap packages
Ubuntu comes pre-configured with snap packages, and it ships with some snap packages by default. In that case, using the apt package manager won't be useful.
The thing is, snaps are updated automatically as it is meant to be a convenient way of installing and managing packages on Ubuntu.
But that doesn't mean you can not update packages manually.
So in this section, I will walk you through how to list the outdated snap packages and how you can update them.
Step 1: List the outdated snap packages
To list the outdated snap packages, you can use the following command:
snap refresh --list
Step 2: Update outdated snap packages
sudo snap refresh
If you want to update a specific package, then use the snap command in the following manner:
sudo snap refresh package_name
For example, if I want to update Firefox, then, I will be using the following:
sudo snap refresh firefox
And if you want to update all the snap packages at once, then use the following command:
sudo snap refresh
Yep, that's all it takes to update snap packages.
Do more with snap updates
Did you know that you can revert to the old version of the snap package if the new version does not work as intended?
Also, you can keep packages from being updated!
Wanna know how? Here's a detailed guide on updating snap packages:
I hope you will find this guide helpful.