0
0
Linux CLIscripting~5 mins

apt (Debian/Ubuntu) basics in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to add or update software on your Debian or Ubuntu computer. The apt tool helps you find, install, and update software easily from the command line.
When you want to install a new program like a text editor or web browser.
When you need to update all the software on your computer to the latest versions.
When you want to remove software you no longer use to free up space.
When you want to check if a program is already installed on your system.
When you want to search for software by name or description before installing.
Commands
This command refreshes the list of available software and their versions from the online sources. It helps your system know about the latest software updates.
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' program, which lets you transfer data from or to a server. It will download and set up curl if it is not already installed.
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 0 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) ...
This command checks if 'curl' is installed by listing it among installed packages.
Terminal
apt list --installed curl
Expected OutputExpected
Listing... Done curl/focal,now 7.68.0-1ubuntu2.7 amd64 [installed]
--installed - Shows only installed packages
This command removes the 'curl' program from your system if you no longer need it.
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 0 not upgraded. After this operation, 500 kB disk space will be freed. (Reading database ... 210000 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 apt, remember: always run 'sudo apt update' before installing or upgrading software to get the latest package information.

Common Mistakes
Trying to install software without running 'sudo apt update' first
Your system may not know about the latest software versions, so it might install an old or missing package.
Always run 'sudo apt update' before 'sudo apt install' to refresh the package list.
Running apt commands without 'sudo'
Installing or removing software requires administrator rights, so the command will fail without 'sudo'.
Use 'sudo' before apt commands that change software, like install or remove.
Confusing 'apt remove' with 'apt purge'
'apt remove' deletes the program but leaves configuration files, which may clutter your system.
Use 'sudo apt purge' if you want to remove the program and its configuration files completely.
Summary
Use 'sudo apt update' to refresh your system's software list before installing or upgrading.
Use 'sudo apt install <package>' to add new software to your system.
Use 'apt list --installed <package>' to check if software is installed.
Use 'sudo apt remove <package>' to uninstall software you no longer need.