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) ...
- Command to know the Available Memory on Linux System
- How to install curl on Alpine Linux
- How to backup a file in Linux/Unix
- Install Java Runtime Environment (Oracle or open JRE) on Ubuntu
- What is the Default Admin user and Password for Jenkins
- How to tar.gz a directory or folder Command
- Copy entire directory using Terminal Command [Linux, Mac, Bash]
- Fix: bash: ipconfig: command not found on Linux
- Command to check Last Login or Reboot History of Users and TTYs
- Linux: Create a New User and Password and Login Example
- ls command to list only directories
- bash: cls: command not found
- How to exit from nano command
- Installing and using unzip Command to unzip a zip file using Terminal
- What does apt-get update command does?
- ls command: sort files by name alphabetically A-Z or Z-A [Linux/Unix/macOS/Bash]
- How to remove or uninstall Java from Ubuntu using apt-get
- scp: ssh: connect to host xxxx port 22: Connection refused Error
- Sort ls command by last modified date and time
- Create Nested Directories using mkdir Command
- How to Exit a File in Terminal (Bash/Zsh)
- Command to know the installed Debian version?
- How to connect to SSH port other than default 22
- How to save a file in Nano Editor and Exit
- Install OpenSSL on Linux/Ubuntu
- Program 15: Find String is a Palindrome or Not - 1000+ Python Programs - Python-Programs
- How to Install CVS Version Control on Linux/Ubuntu - Linux
- How to know the Version of Notepad App on Windows 11 - Windows-11
- Comprehensive 256 Ascii code table with Html Hex IBM Microsoft Key - Html
- [Solved] SharePoint Search Internal server error exception - SharePoint
- How To Remove Only Conditional Formatting in Excel - Microsoft
- How to reset AirPods or AirPods Pro using iPhone/iPad or iPod - iOS