On Ubuntu and Debian, programs come as packages from the official package sources. apt finds, installs, updates and removes them, together with everything they need. The commands were tested on Ubuntu 26.04 LTS with the small program tree as an example. On Debian 13 we installed the programs for our other guides with the same commands. Run them as root or with sudo.
1. Refresh the Package List
apt update
This downloads the current list of packages; it does not install anything yet. Run it before you install something new.
2. Find a Program
apt search tree: every package with "tree" in its name or description.apt search --names-only "^tree$"looks only for that exact name.apt show tree: description, version and size.apt policy tree:Installed: (none)if it is not installed, and theCandidateversion that would be installed.
3. Install
apt install tree
apt shows what it will install and asks for confirmation; answer Y. It ends with lines like Setting up tree (2.3.1-1). The program can be used at once: tree -L 1 /etc/ssh shows the folder as a tree.
4. Update Everything
apt update apt upgrade
More about updates, automatic security updates and when a restart is needed: Automatic Security Updates on Ubuntu and Debian.
5. Remove
apt remove tree: removes the program and keeps its settings files.apt purge tree: removes the program and its settings files.apt autoremove: removes packages that were installed only as helpers for programs you have removed. Read the list before you confirm.
After apt purge tree, which tree finds nothing.
Useful Questions
- Is it installed?
apt list --installed | grep '^tree/'shows[installed]. - Which package does a file come from?
dpkg -S /usr/bin/treeanswerstree: /usr/bin/tree. - What did I install recently?
grep "Commandline" /var/log/apt/history.loglists the install and remove commands.
Install programs from the official package sources of Ubuntu or Debian whenever possible. Add other sources or download installation scripts only from the official website of the program: they run with full rights on your server.