0
0
Linux CLIscripting~5 mins

Installing, updating, removing packages in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Managing software on your Linux system means adding new programs, keeping them current, or removing ones you no longer need. This helps your computer stay useful, secure, and clean.
When you want to add a new tool or application to your Linux system.
When you need to update existing software to get new features or security fixes.
When you want to free up space by removing software you no longer use.
When troubleshooting software issues by reinstalling or removing packages.
When preparing your system for a new project that requires specific software versions.
Commands
This command refreshes the list of available software and their versions from the online sources. It ensures your system knows about the latest packages before installing or updating.
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, 500 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) ...
-y - Automatically answer yes to prompts during installation
This command upgrades all installed packages to their latest versions. It helps keep your system secure and up to date.
Terminal
sudo apt upgrade
Expected OutputExpected
Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages will be upgraded: libc-bin libc6 2 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 2,500 kB of archives. After this operation, 1,024 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libc6 amd64 2.31-0ubuntu9.9 [2,000 kB] Get:2 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 libc-bin amd64 2.31-0ubuntu9.9 [500 kB] Fetched 2,500 kB in 2s (1,250 kB/s) (Reading database ... 210000 files and directories currently installed.) Preparing to unpack .../libc6_2.31-0ubuntu9.9_amd64.deb ... Unpacking libc6:amd64 (2.31-0ubuntu9.9) over (2.31-0ubuntu9.8) ... Setting up libc6:amd64 (2.31-0ubuntu9.9) ... Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
-y - Automatically confirm upgrade without asking
This command removes the 'curl' package from your system. It deletes the software but keeps configuration files in case you want to reinstall later.
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, 500 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 210000 files and directories currently installed.) Removing curl (7.68.0-1ubuntu2.7) ... Processing triggers for man-db (2.9.1-1) ...
-y - Automatically confirm removal without asking
Key Concept

If you remember nothing else from this pattern, remember: always update your package list before installing or upgrading software to get the latest versions.

Common Mistakes
Trying to install or upgrade packages without running 'sudo apt update' first.
Your system may not know about the latest software versions, causing errors or installing outdated packages.
Always run 'sudo apt update' before installing or upgrading packages.
Not using 'sudo' with package management commands.
Without administrative rights, the commands will fail because installing or removing software needs special permissions.
Prefix package commands with 'sudo' to run them as an administrator.
Using 'apt remove' when you want to completely delete software including configuration files.
'apt remove' leaves configuration files behind, which may cause conflicts or use disk space.
Use 'sudo apt purge package-name' to remove software and its configuration files completely.
Summary
Run 'sudo apt update' to refresh the list of available software before any install or upgrade.
Use 'sudo apt install package-name' to add new software to your system.
Use 'sudo apt upgrade' to update all installed software to the latest versions.
Use 'sudo apt remove package-name' to uninstall software but keep configuration files.