The ‘sudo apt update’ command is the most essential command in Linux to keep a system healthy and up-to-date. This command installs and downloads all the latest package information available for the packages currently installed on the system. This article comprehensively covers the sudo apt update command, its functionality, and its operations. Besides, the output of the command will be appropriately described.
Key Takeaways
- Knowing how the sudo apt update command updates the package list in the Linux system.
- Analyzing the output to realize what process the system is following to achieve the latest version of the packages.
- Unleashing the way to set up automatic updates in the Linux system.
Requirements
- You must need to be a sudo/root user or need to have root privilege.
- Your Linux system should have the correct package manager (for Ubuntu it’s ‘apt’).
Basics of sudo apt update Command
In Linux-based operating systems, particularly Ubuntu, the sudo apt update command essentially serves as an instruction to update the local package index. It downloads package details from all set sources to refresh the package cache. The package manager (in this case apt) needs to know which packages are available and where to find them to install software or packages on your system.
What is sudo?
The term sudo, which stands for ‘Superuser Do’, is a powerful utility, used in Linux and Unix-based operating systems. The ‘superusers’ or ‘root’ are the authorized users who get the elevated privilege to execute specific administrative commands and get the permissions to carry out any operations on the system. When you run the command sudo in your terminal, you temporarily get permission to perform tasks beyond your boundaries as a regular user. Before providing access, the command asks for a password to confirm your identity. The basic syntax of the sudo command is as follows:
sudo [OPTION] COMMAND [ARGUMENTS..]
To learn more read: The “sudo” Command in Linux [8 Practical Examples]
What is sudo apt?
Here the second term apt stands for Advanced Package Tool which is the library for package management systems used in Linux distributions. The keyword apt is used to call the apt repository which permits the users to install, update or remove packages from the repositories of software distributions. The sudo apt allows a root user to perform operations in the apt repository.
sudo apt install <package_name>
Here, in the place of <package_name>, you have to give the specific package name you want to install. This command downloads the latest version available for the mentioned package name.
What does the sudo apt update Command Do?
The sudo apt update command instructs the package manager to obtain the most recent package information from the software repositories to update the local package database. When you run sudo apt update the package manager searches for new updates or new software packages and then changes the existing local database of software packages.
Update Cache in Ubuntu Using APT
The ‘apt cache’ or ‘package cache’ both terminology refer to a local database that stores information about available software packages, including their names, versions, dependencies, and other metadata. Updating the ‘apt’ cache means refreshing the local database of available software packages and their metadata on your Linux system. This term indicates the process of updating packages using the sudo apt update command.
sudo apt update
After running the ‘sudo apt update’ command, your apt package cache will be up-to-date ensuring your system has the latest package information.
2 Practical Cases of Using the ‘sudo apt update’ Command in Linux
In this section, I’m going to make you familiar with the real scenarios of the ‘sudo apt update’ command and its functionality including its output breakdown. Here, you will get to know two scenarios to update your system both manual and automatic update setup.
Case 01: Manual Update Using the ‘sudo apt update’ Command
Here I’ll show how to run the command in the terminal in Ubuntu step by step. Then I’ll explain what the output of the command indicates including the description of each marked term.
Steps to Follow >
➊ Open the Ubuntu terminal.
➋ Write the following command to update your package manager.
sudo apt update
➌ Provide your root password and immediately you will start receiving the following statements.
From the image, you can notice the output of the command sudo apt update for updating packages that have been updated successively. Here you can see the package repository to update is http://bd.archieve.ubuntu.com/ubuntu which has been reached successfully.
I have explained the underlined data of the two above images:
Case 02: Automatic Update Set-up Using the ‘sudo apt update’ Command
As it’s essential and rigorous to update your system packages regularly to have a secure and stable environment, it can be convenient for the users to set up an automatic update. Automatic updates in Ubuntu give you the privilege to get the process of downloading and installing software updates done without any manual intervention. If you want to automate the process of updating your installed packages, you can follow the steps stated below
Steps to Follow >
➊ Open the Ubuntu terminal or press CTRL+ALT+T.
➋ Run the following command to install the unattended-upgrades package.
sudo apt-get install unattended-upgrades
➌ Now, run the following command to edit the configuration file.
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
You can also uncategorize packages to which you don’t want auto update activated.
You can also edit the file to achieve multiple purposes. Such as:
- If you want to get notifications in email, scroll down and find the 1st highlighted line. Now enter a valid email address within the quotation mark “ “ and remove the preceding double slashes.
- To get a notification in case of any update gets wrong, uncomment the 2nd highlighted line and modify the attribute “on-change” to “only-on-error”
- To remove unused kernel and new unused dependencies, just uncomment the 3rd and 4th highlighted lines.
If you want to auto-reboot your system after updating then replace “false” with “true” at the ‘6’ marked line and uncomment the line to execute. You can also modify the auto-reboot time at your convenience at the ‘8th’ highlighted line.
➍ Save the file and then exit by pressing CTRL+S and CTRL+X respectively after completing all the modifications you need.
➎ Finally, enable automatic updates by editing the “10auto-upgrades files as directed below. To access the file run the following command.
sudo nano /etc/apt/apt.conf.d/20aut-upgrades
This file contains only two lines that enable automatic updates and upgrades. The two lines are:
- APT : : Periodic : : Update-Package-Lists “1”;
- APT : : Periodic : : Unattended-Upgrade “1”;
The first line is for the auto-update of the package lists and the second line initiates the auto-upgrade of the packages. The numerical value quoted in both lines can be “1” or “0” where 1 enables auto update and upgrade and 0 disables that.
Conclusion
To conclude, for Ubuntu-based Linux systems, sudo apt update is crucial in maintaining a robust environment. It ensures updated installations and downloads for existing packages. I hope that the essay has helped you better to understand.
People Also Ask
Related Articles
- [Fixed] sudo apt update Not Working Error in Ubuntu
- [Fixed] sudo apt-get update Not Working in Ubuntu
- [Fixed] APT-Get Update Failed to Fetch Error in Linux
- How to Update RPM Packages in RHEL? [6 Methods]
- How to Check Updates Using YUM on RHEL? [5 Practical Cases]
- How to Update All Packages in RHEL Using YUM? [3 Cases]
- How to Update a Specific Package in RHEL Using YUM? [2 Cases]
<< Go Back to Update Packages in Linux | Package Management in Linux | Learn Linux Basics