Debian: apt & dpkg

Debian / Ubuntu - apt & dpkg

apt is the everyday tool on Debian-family systems (Debian, Ubuntu, Mint). It talks to remote repositories, so before installing anything for the first time in a session, you generally refresh its local knowledge of what's available:

TaskCommand
Refresh repo metadataapt update
Upgrade all packagesapt upgrade
Installapt install <pkg>
Remove (keep config)apt remove <pkg>
Remove + configapt purge <pkg>
Searchapt search <term>
Install a local .debdpkg -i file.deb
List installeddpkg -l
Which package owns a filedpkg -S /path
List a package's filesdpkg -L <pkg>

apt update doesn't install or upgrade anything by itself - it only downloads the current list of what versions are available, from the repositories configured in /etc/apt/sources.list and /etc/apt/sources.list.d/. Skipping it means apt install might try to fetch a package version that no longer exists on the server.

$ apt update && apt install -y tree
$ dpkg -S /bin/ls
coreutils: /bin/ls

That dpkg -S example answers a question you'll ask constantly while debugging: "which package do I blame (or reinstall) for this file?" Here, /bin/ls turns out to belong to the coreutils package.

Warning: If you download a .deb file directly and dpkg -i file.deb fails complaining about missing dependencies, dpkg will not go fetch them for you - remember, it's the low-level tool. The fix is apt-get install -f ("fix broken"), which hands the problem to the high-level tool so it can pull in whatever was missing from the repositories.