apt/dpkg Cheatsheet
apt
apt
can be considered a front-end to dpkg
.
apt
is a simplified command that combines the most commonly used command options from apt-get
and apt-cache
.
apt Commands
$ sudo apt install <package>
$ sudo apt install <package>=<version> # Install a specific version
$ sudo apt search <package>
$ sudo apt show <package>
$ sudo apt update
$ sudo apt list --upgradable
$ sudo apt list --installed
$ sudo apt upgrade
$ apt-cache stats: get stats of the packages
$ apt-cache pkgnames | grep docker
How to list available packages
# list available packages
$ apt-cache search KEYWORD
# e.g. search for Chrome
$ apt-cache search google-chrome
google-chrome-stable - The web browser from Google
$ apt install google-chrome-stable
apt update vs apt upgrade vs apt dist-upgrade
apt update
will only check the latest versions of the packages, without actually downloading package updates;apt upgrade
will do the actual upgrading;apt dist-upgrade
is for upgrading the OS itself.
dpkg (Debian Package Manager)
Install a local .deb
package in Ubuntu:
$ dpkg -i filename.deb
List pakcages:
$ dpkg -l
Check all installed packages
$ dpkg --get-selections
$ dpkg --get-selections | grep mongo
dpkg
is a backend-ish tool, usually we do not need to use it directly. Check other options in $ man dpkg
.
check where the command is coming from
$ dpkg -S /bin/ls
$ dpkg -S $(which ls)
$ dpkg -S /usr/bin/ssh
openssh-client: /usr/bin/ssh
$ dpkg -S /bin/grep
grep: /bin/grep
Note that
-S
for search-s
for status
Get details about the package:
$ dpkg -s coreutils
coreutils: /bin/ls
error: parsing file ... near line 0
Error:
dpkg: error: parsing file '/var/lib/dpkg/updates/0004' near line 0:
Verify:
$ head /var/lib/dpkg/updates/0004
#padding
#padding
#padding
#padding
Fix:
$ cd /var/lib/dpkg/updates && rm -rf 0004
$ sudo dpkg --configure -a
FAQ
Where do the packages come from?
They come from "repositories" listed in
/etc/apt/sources.list
/etc/apt/sources.list.d/
Personal Package Archives (PPAs) are software repositories designed for Ubuntu users and are easier to install than other third-party repositories. PPAs are often used to distribute pre-release software so that it can be tested.
Where to find apt/dpkg history?
The apt history is in /var/log/apt/history.log
To see all the packages that went through dpkg
, you can look at /var/log/dpkg.log
.