Linux Commands

Understanding the Linux Apt-Get Update Command

When starting with Linux, the terminal commands can get overwhelming. Often, when you need to install any tool and do a search online, you will note that the apt-get update command gets listed. Executing the apt-get command paves the way for installing your tool. Do you know what the apt-get update does? Or why do most tutorials list the command before installing other packages? This guide covers everything you need to know about apt-get updates in Linux.

Breaking Down the apt-get update Command

First, to run the apt-get update command, you must have administrator privileges. When you run the command, you should get an output similar to the one below:

$ sudo apt-get update


In the above, sudo (super-user-do) gives you administrator privileges, but if you are running as root, you don’t need to include it.

Ubuntu and Linux are open-source and run on the Linux kernel. The kernel uses the apt or apt-get GNU commands to manage the packages and software. You can add, remove, or update any installed packages with either of the commands.

Therefore, apt-get update downloads the information for all packages listed in the sources file. When you run the command, it instructs the kernel to use the configured sources to update the package information.

Also, you will note various keywords, including Get, Hit, and Ign. The Get indicates that there are versions of the package available. Hit suggests no change in the package, and Ign means a given package has been ignored. When all packages update their information, the last line indicates everything is up-to-date, as shown below.


The configured sources get defined in the sources.list file and you can open it using an editor or other commands. All packages available for installation for the current kernel version are contained in the source list. The package information includes the location of each repository from where a package can be sourced and installed.

$ sudo nano /etc/apt/sources.list


The configured sources are different depending on the kernel version you are running. The kernel uses the configured sources and gets the latest version of each package. Only the lines not commented, with a # before them, get executed. They are the URLs indicating where to source the package information.

Why Run apt-get update Before Installing Packages on Linux?

You’ve noticed that before installing packages on Linux, you need to run apt-get update. It is recommended to do so since your kernel has no idea if the current version of the installed programs is the latest. It can only know by updating the package information using the apt-get command. Similarly, before you upgrade, you should first update the package information also, unless you update the sources list.

Conclusion

The apt-get update or apt update Linux commands are used to update the package information. We’ve covered the command in detail and how you can use it to update all the installed packages in your Linux system. Besides, if you need to install or upgrade your packages, it’s recommended to run apt-get update.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.