Software and users

Install and remove packages

Search, inspect, install, remove, and clean packages without copying an unknown installation script into a root shell.

8 minute lesson

~~~

Search for a package and inspect it before installing:

apt search '^tree$'
apt show tree

The description, repository, download size, and dependencies help you confirm that you found the intended package.

Install it with:

sudo apt install tree

Read the transaction summary before confirming. If APT proposes removing unrelated packages or changing a large part of the system, stop and investigate.

Remove, purge, and autoremove

These commands have different effects:

sudo apt remove tree
sudo apt purge tree
sudo apt autoremove

remove deletes the installed program but can keep package-managed configuration. purge removes that configuration too. Neither command promises to remove data the application created in your home directory or under /var/lib.

autoremove proposes dependencies that APT considers no longer required. Review the list. Do not accept a surprising removal just because the command describes the packages as automatic.

Prefer known package sources

Use Ubuntu repositories when they contain a suitable version. A command such as this deserves extra scrutiny:

curl https://vendor.invalid/install.sh | sudo sh

It downloads changing code and executes it as root without giving you a review point. If you need a third-party repository, use the vendor’s current official instructions, understand its signing key and repository scope, and record how to remove it later.

Verify what was installed

Check the binary and package record:

command -v tree
dpkg -L tree | less
apt policy tree

After removal, check whether the service, configuration, and application data you intended to remove are truly gone.

Try this: inspect one small package, write down every package APT proposes adding, install it, verify the binary, then remove it on a test machine.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →