Skip to content

The apt command

The apt command installs, updates and removes software on Ubuntu and Debian…

The apt command installs, updates and removes software on Ubuntu and Debian: sudo apt update refreshes the lists, and sudo apt install tree adds a program.

Taught in Advanced, lesson 44

A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.

Usage

sudo apt update
sudo apt install PACKAGE...
sudo apt remove PACKAGE...
apt search WORD
apt list --installed
apt show PACKAGE

Install, remove and search for software (Ubuntu and Debian). apt is the package manager on Ubuntu and Debian: it downloads programs from the distribution’s servers and installs them with everything they need. apt update refreshes the list of what is available; apt install adds a program, after which its command works (sudo apt install tree, then tree). Installing and removing need sudo. In this practice shell nothing is downloaded: apt knows a small pretend catalogue (tree, htop, net-tools, nginx, cowsay, ripgrep and the base system). Everything here is simulated in the page: no real accounts, passwords or software are involved.

In the practice terminal:Nothing is downloaded: the practice apt installs from a small pretend catalogue (tree, htop, net-tools, nginx, cowsay and ripgrep) inside the page.

How to use apt

Install a program

apt downloads it with anything it needs, and then its command works.

sudo apt install tree
[sudo] password for learner: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  tree
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 47.9 kB of archives.
After this operation, 116 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu noble/main amd64 tree amd64 2.1.1-2ubuntu3 [47.9 kB]
Fetched 47.9 kB in 0s (47.9 kB/s)
Selecting previously unselected package tree.
… and 4 more lines
tree projects
projects
├── app
│   ├── config
│   │   └── settings.yml
│   └── main.js
├── config
└── notes
    └── ideas.txt

4 directories, 3 files

Refresh the lists, then upgrade

update fetches the latest lists of packages and installs nothing. upgrade then installs newer versions of what you have.

sudo apt update
[sudo] password for learner: 
Hit:1 http://archive.ubuntu.com/ubuntu noble InRelease
Get:2 http://archive.ubuntu.com/ubuntu noble-updates InRelease [126 kB]
Get:3 http://security.ubuntu.com/ubuntu noble-security InRelease [126 kB]
Fetched 252 kB in 1s (252 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
sudo apt upgrade
[sudo] password for learner: 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Search for a package and read about it

apt search tree
Sorting... Done
Full Text Search... Done
tree/noble 2.1.1-2ubuntu3 amd64
  displays an indented directory tree, in color

apt show htop
Package: htop
Version: 3.3.0-4build1
Priority: optional
Section: universe/utils
Origin: Ubuntu
Installed-Size: 434 kB
Download-Size: 171 kB
APT-Manual-Installed: no
Description: interactive processes viewer

Remove a program

After sudo apt install tree: remove takes it away but keeps its settings files, and purge deletes those too.

sudo apt remove tree
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  tree
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 116 kB disk space will be freed.
Removing tree (2.1.1-2ubuntu3) ...

When a command is not found

Ubuntu suggests the package that has it.

tree
Command 'tree' not found, but can be installed with:
sudo apt install tree

See what is installed

apt list --installed | head -5
Listing... Done
bash/noble,now 5.2.21-2ubuntu4 amd64 [installed]
bind9-dnsutils/noble,now 1:9.18.28-0ubuntu0.24.04.1 amd64 [installed]
coreutils/noble,now 9.4-3ubuntu6 amd64 [installed]
cron/noble,now 3.0pl1-184ubuntu2 amd64 [installed]

Options

updaterefresh the list of packages
installinstall packages
remove, purgeremove packages
upgradeupgrade everything installed
search WORDfind packages
list --installedwhat is installed
show PACKAGEdetails of one package
-ydon’t ask before installing

Questions about apt

What is the difference between apt and apt-get?

apt is the newer, friendlier front end, with a progress bar and colour. apt-get is the older one, which scripts use because its output never changes. They install the same packages.

What is the difference between apt update and apt upgrade?

update downloads the latest lists of what is available and changes nothing. upgrade installs newer versions of your packages. Run update first.

What does "are you root?" mean when apt fails?

Installing and removing change the system, so they need sudo: sudo apt install name.

What do Fedora and Arch use instead of apt?

Fedora uses dnf (sudo dnf install name) and Arch uses pacman (sudo pacman -S name). The ideas are the same.

Learn it step by step

Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.