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) ...
- How to Display content of a file in Terminal Screen?
- How to Install CVS Version Control on Linux/Ubuntu
- How to install and Configure sar sysstat tools in Ubuntu Linux
- ls command to list only directories
- [Ubuntu] Search a package and versions using apt command
- zsh hello world example
- Linux Remove or Delete Files and Directories using Terminal Commands
- How to tar.gz a directory or folder Command
- Calculate days between dates using dateutils ddiff command
- How to ls command to output one entry per line [macOS/Linux/Bash]
- 3 Commands to stop Nginx Server
- Create and write file in single Linux/macOS command
- SCP Copy all files from directory to Local Folder
- How to go to the End of File in Nano Editor
- How to remove/delete a directory in Linux/macOs
- How to Copy Entire Directory to another Directory in Linux
- Execute .bin and .run file Ubuntu Linux
- The Date Command and its usage [Linux - Unix - macOS]
- Fix - ssh-copy-id no identities found error
- How to check uptime of Linux/Unix/macOS system/server using console command?
- How to Select All text in vim/vi editor using Keyboard
- Linux: Create a New User and Password and Login Example
- Command to display epoch time Terminal
- How to install curl on Alpine Linux
- How to exit from nano command
- Mac OS X Taking Screen Capture using Terminal - Mac-OS-X
- Setup synonyms or alias or thesaurus in SharePoint - SharePoint
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted. - Android
- Fix - SharePoint Online List column JSON formatting for person group field displays [object, Object] - SharePoint
- [fix] psycopg2 Error: pg_config executable not found - Python
- How to enable, create and use Virtual Breakout Rooms in Microsoft Teams - Teams
- How to query database table names [MySQL/Oracle/SQL Server] - MySQL
- [fix] RabbitMQ: AuthenticationFailureException ACCESS_REFUSED Login refused authentication mechanism PLAIN - 2022