
apt-get update - Retrieve new lists of packages
You many have noticed that most of the examples where you have to install a new package, apt-get update command is used before doing an apt-get install, if you are wondering why we need to make use of this command, lets find out.
apt-get is a package manager for Debian, and Debian-based Linux. When you try to look or install a package it first looks at the list of the packages that are available at the repository from which it downloads the packages. This list is stored locally on your system. If this list is not up to date, you will get an error saying Unable to locate package.
Let's see an example, I have installed a fresh Ubuntu Linux OS in a container, its a minimal OS that does not have all commands installed, not even Sudo, so when I run any command with sudo I get "sudo: not found", if I try to use the apt-get command to install sudo I still get an error,
# apt-get install sudo
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package sudo
#
This is because the local package list does not have information about sudo, if I run apt-get update and then try to install it, it works!
# apt-get update
Get:1 http://ports.ubuntu.com/ubuntu-ports focal InRelease [265 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports focal-updates InRelease [114 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports focal-backports InRelease [108 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports focal-security InRelease [114 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports focal/restricted arm64 Packages [1317 B]
Get:6 http://ports.ubuntu.com/ubuntu-ports focal/main arm64 Packages [1234 kB]
Get:7 http://ports.ubuntu.com/ubuntu-ports focal/multiverse arm64 Packages [139 kB]
Get:8 http://ports.ubuntu.com/ubuntu-ports focal/universe arm64 Packages [11.1 MB]
Get:9 http://ports.ubuntu.com/ubuntu-ports focal-updates/multiverse arm64 Packages [9090 B]
Get:10 http://ports.ubuntu.com/ubuntu-ports focal-updates/universe arm64 Packages [1079 kB]
Get:11 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 Packages [1433 kB]
Get:12 http://ports.ubuntu.com/ubuntu-ports focal-updates/restricted arm64 Packages [3933 B]
Get:13 http://ports.ubuntu.com/ubuntu-ports focal-backports/main arm64 Packages [51.1 kB]
Get:14 http://ports.ubuntu.com/ubuntu-ports focal-backports/universe arm64 Packages [26.0 kB]
Get:15 http://ports.ubuntu.com/ubuntu-ports focal-security/restricted arm64 Packages [3694 B]
Get:16 http://ports.ubuntu.com/ubuntu-ports focal-security/main arm64 Packages [1076 kB]
Get:17 http://ports.ubuntu.com/ubuntu-ports focal-security/universe arm64 Packages [796 kB]
Get:18 http://ports.ubuntu.com/ubuntu-ports focal-security/multiverse arm64 Packages [3254 B]
Fetched 17.6 MB in 14s (1219 kB/s)
Reading package lists... Done
As you can see when I ran apt-get it fetched around 17.6 MB of information about the packages available for my arm64 based system and updated it locally.
Now lets try to install sudo command,
# apt-get install sudo
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
sudo
Preparing to unpack .../sudo_1.8.31-1ubuntu1.2_arm64.deb ...
Unpacking sudo (1.8.31-1ubuntu1.2) ...
Setting up sudo (1.8.31-1ubuntu1.2) ...
- [Fix] Linux - bash: useradd: command not found
- Calculate days between dates using dateutils ddiff command
- pwd Command - Print Working Directory
- Rename a directory using Linux/Unix command
- How to go to the End of File in Nano Editor
- How to tar.gz a directory or folder Command
- How to remove/delete a directory in Linux/macOs
- How to Display content of a file in Terminal Screen?
- ls command sort by file size [Linix/UNIX/macOS/bash]
- How to Copy Entire Directory to another Directory in Linux
- 3 ways to clear screen on Linux Terminal
- Command to check Last Login or Reboot History of Users and TTYs
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to backup a file in Linux/Unix
- Command to know the installed Debian version?
- Check SSH/OpenSSH version Command
- 3 Commands to stop Nginx Server
- Linux: Create a New User and Password and Login Example
- How to install npm on Ubuntu
- How to List All Users in Linux
- How to Get the List of Shells on Linux
- Fix - ssh-copy-id no identities found error
- Installing and using unzip Command to unzip a zip file using Terminal
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- zsh hello world example
- [fix] macOS Ventura - Python3 xcrun: error: invalid active developer path missing xcrun at CommandLineTools - MacOS
- list of jars required for hibernate 4.x.x - Java
- How to create Toast messages in Android? - Android
- [fix] Chrome: no listeners for an event URLS_SAFE_CHECK__STATUS_UPDATED - Chrome
- Notepad++ Mark and Copy feature - NotepadPlusPlus
- groovy.lang.MissingPropertyException No such property Error - Android-Studio
- Android Studio Ctrl Shift o auto import not working - Android
- Android Studio 4.2 Canary 1 now available - Android-Studio