0
0
Linux CLIscripting~5 mins

Repository management in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Managing repositories on a Linux system helps you organize and access software packages easily. It solves the problem of installing, updating, and removing software in a controlled way.
When you want to install new software that is not already on your system.
When you need to update existing software to the latest version.
When you want to remove software cleanly without leftover files.
When you want to check which software packages are installed.
When you want to add or remove software sources to get different versions.
Commands
This command refreshes the list of available software packages from the repositories. It ensures your system knows about the latest versions.
Terminal
sudo apt update
Expected OutputExpected
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease Get:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:3 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB] Fetched 215 kB in 1s (300 kB/s) Reading package lists... Done
This command installs the 'curl' package, a tool to transfer data from or to a server. It downloads and sets up the software on your system.
Terminal
sudo apt install curl
Expected OutputExpected
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: curl 0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded. Need to get 159 kB of archives. After this operation, 456 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 curl amd64 7.68.0-1ubuntu2.7 [159 kB] Fetched 159 kB in 1s (200 kB/s) Selecting previously unselected package curl. (Reading database ... 210000 files and directories currently installed.) Preparing to unpack .../curl_7.68.0-1ubuntu2.7_amd64.deb ... Unpacking curl (7.68.0-1ubuntu2.7) ... Setting up curl (7.68.0-1ubuntu2.7) ... Processing triggers for man-db (2.9.1-1) ...
This command lists all installed packages and filters the list to show only those with 'curl' in the name. It confirms that curl is installed.
Terminal
apt list --installed | grep curl
Expected OutputExpected
curl/focal-updates,focal-security,now 7.68.0-1ubuntu2.7 amd64 [installed]
--installed - Lists only installed packages
This command removes the 'curl' package from your system. It deletes the software but keeps configuration files.
Terminal
sudo apt remove curl
Expected OutputExpected
Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: curl 0 upgraded, 0 newly installed, 1 to remove and 5 not upgraded. After this operation, 456 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 210500 files and directories currently installed.) Removing curl (7.68.0-1ubuntu2.7) ... Processing triggers for man-db (2.9.1-1) ...
Key Concept

If you remember nothing else from repository management, remember: always update your package list before installing or upgrading software.

Common Mistakes
Trying to install software without running 'sudo apt update' first
The system may not know about the latest packages and fail to find or install the software.
Run 'sudo apt update' before installing new packages to refresh the package list.
Removing software without checking dependencies
Removing a package might break other software that depends on it.
Check dependencies with 'apt depends package-name' before removing important software.
Using 'apt remove' when you want to completely delete software including config files
'apt remove' leaves configuration files behind, which might cause conflicts later.
Use 'sudo apt purge package-name' to remove software and its configuration files.
Summary
Use 'sudo apt update' to refresh the list of available software packages.
Install software with 'sudo apt install package-name' and verify installation with 'apt list --installed'.
Remove software cleanly with 'sudo apt remove package-name' or 'sudo apt purge package-name' to delete configs.