How to Update Ubuntu Using Command Line?
Ubuntu as a whole has a specific release cycle that offers an LTS version every two years (The next LTS will be Ubuntu 24.04 NobleNumbat) and a rolling release every 6 months. However, the packages supported by Ubuntu have multiple contributors. These contributors keep on providing updates to the existing versions to meet the technological evolution. Therefore, the users must keep on checking and updating their Ubuntu to load/install the latest updates, as soon as they are loaded.
Being a Linux-based system, Ubuntu and its users strongly rely on command-line support. So, this post will list the possible methods to update Ubuntu using the command line.
How to Update Ubuntu Using Command Line?
How to Update Specific Package(s) on Ubuntu?
How to Update Ubuntu Remotely Using Command Line?
Bonus Tip: How to Update Ubuntu Using GUI?
How to Update Ubuntu Using Command Line?
Updates in Ubuntu refer to updating the packages, kernel, or any dependencies that are associated with the packages. Remember, a root user or the user having the sudo privileges can perform the updates. Let’s start the updating process:
Step 1: Update the Packages List
The update command loads the packages in the repositories list:
$ sudo apt update
As per the output, 468 packages on our system can be upgraded.
Step 2: Install all the Loaded Updates
Once the updates are loaded, the users have two ways to install those updates. Choose as per your requirement:
Using the apt upgrade
Use the upgrade command to install all those updates. The apt upgrade will install the updates of the packages without dealing with the dependencies (if they are useless):
$ sudo apt upgrade
The output shows that the command does not remove the packages automatically. Moreover, it holds some packages whose updated dependencies are required but are unavailable on the system (it does not install them automatically).
Using apt dist-upgrade
The dist-upgrade will install dependencies associated with the packages being upgraded. It also removes the package’s dependencies if they are not required further (useless). Apart from that, it also deals with the system’s security patches update.
$ sudo apt dist-upgrade
Note: Using the “sudo apt dist-upgrade” every time is not recommended as the system could crash in resolving dependencies and most importantly upgrading the Kernel. Ensure you have either backed up the system configurations or you are running the command in the test environment. Alternatively, the “sudo apt full-upgrade” also serves the same functionality as the above command.
Note: Instead of using update and upgrade separately, the following one-liner command will update as well as install those updates on your system:
$ sudo apt update && sudo apt upgrade
Step 3 (Optional): Remove Unnecessary Installations
While performing an Ubuntu update, it is recommended to autoremove the useless package dependencies (It only removes those dependencies/packages whose associated packages were deleted):
$ sudo apt autoremove
Step 4 (Optional): Clean the Cache
The packages that cannot be downloaded and are useless are recommended to be cleaned from the local repository. The apt autoclean command serves the purpose of keeping your system clean:
$ sudo apt autoclean
How to Update Specific Package(s) on Ubuntu?
The above method will install all the updates of the loaded packages. What if you only want to update one package? Ubuntu also allows you to do so. Let’s see how it can be done:
Step 1: List the Available Updates
Use the command below to list the packages that can be upgraded:
$ sudo apt list –upgradeable
A long list of packages with their names and the version to which these packages can be upgraded. The upgradeable version is also provided at the end of each package’s name, i.e., [upgradable from: 1.2.6.3-1ubuntu1].
Step 2: Install the Update
Pick the package name to be updated and use the following command to install the update, i.e., the package in our case is, thunderbird:
$ sudo apt install –only-upgrade thunderbird
The image shows three Thunderbird-related packages that have been upgraded.
How to Update Ubuntu Remotely Using Command Line?
Ubuntu system can be accessed remotely to perform various operations, i.e., update, and upgrade. SSH is the most used and recommended way to access your Ubuntu Desktop/Server. The users can connect to their (or any other system) system via SSH to update Ubuntu. The process is as follows:
Prerequisites: Install and Configure the SSH Support
The host and the client system must have the SSH server and client support installed. If not, use the following command(s) separately on the host and client side:
$ sudo apt install ssh
Now, enable the firewall using the ufw command:
$ sudo ufw enable
Allow the ssh connections through the ufw command:
$ sudo ufw allow ssh
Reload the firewall rules via the command:
$ sudo ufw reload
Step 1: Establish the SSH Connection
After installing/configuring the SSH, use the below-stated command to connect to the remote machine (the username and the hostname refer to the remote machine on which the updating will be carried out):
Syntax:
$ ssh username@IP-Address
In our case, the following parameters are used:
- Debian 12 is used as a host machine to connect to Ubuntu remotely.
- The Username of the Ubuntu machine is “adnan” and the IP address is “192.168.18.88”.
So, the command would be:
$ ssh [email protected]
Step 2: Load/Install the Updates
Once you are connected, use the following one-liner update/upgrade command to load and install the updates at once:
$ sudo apt update && sudo apt upgrade
The updates are completed on the Ubuntu machine by accessing it remotely via SSH.
Bonus Tip: How to Update Ubuntu Using GUI?
Until now, we have demonstrated the process of updating Ubuntu using the command line support. As Ubuntu comes with a Desktop environment, the users can also utilize Desktop support to update the system. Let’s dig into it:
Step 1: Launch the Software Updater
Ubuntu has a built-in GUI application named Software Updater, which is used to update Ubuntu using the GUI. Search for the Software Updater in the applications menu and launch it.
When launched, it will start looking for available updates:
Step 2: Install the Updates
Once the updates are loaded, the following window appears. Click on the “Details of updates” to check which types of updates are available (the users can uncheck if any update is not required). Now, click on the “Install Now” button to start the installation:
Provide the user’s password to proceed with the updating process:
The installation of the updates and the details can be seen on the following screen:
Once the updates are installed, a prompt appears that asks you to remove some unused packages, as shown below:
That’s how the Ubuntu updates are carried out.
Bottom Line
The apt update command loads/synchronizes the packages list with the updates available online. To install the loaded updates, the apt upgrade or apt dist-upgrade command is used. Apart from these, the users have the option to update the system remotely by accessing the system from another system via SSH, as illustrated above.
This post has listed the potential methods to update Ubuntu from its command line support. Apart from only CLI method(s), you have also learned how to update Ubuntu using the GUI.