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:
| Task | Command |
|---|---|
| Refresh repo metadata | apt update |
| Upgrade all packages | apt upgrade |
| Install | apt install <pkg> |
| Remove (keep config) | apt remove <pkg> |
| Remove + config | apt purge <pkg> |
| Search | apt search <term> |
| Install a local .deb | dpkg -i file.deb |
| List installed | dpkg -l |
| Which package owns a file | dpkg -S /path |
| List a package's files | dpkg -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.debfile directly anddpkg -i file.debfails complaining about missing dependencies,dpkgwill not go fetch them for you - remember, it's the low-level tool. The fix isapt-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.