The ultimate guide for using the Apt package manager

Apt is the package manager for Debian/Ubuntu/Linux Mint and other debian based distros. It is good because it solves the dependences. Use dpkg to install packages just if the installation failed with apt.

Watch Free Movies

1. Searching the repositories for the packages you want to install: apt-cache search

with apt-cache search you can search packages by name or description.

Searching for packages by description:

$ apt-cache search minesweeper | head -3
ace-of-penguins - penguin-themed solitaire games
freesweep - text-based minesweeper - Minesweeper for GNU

Searching for packages by name:

$ apt-cache search ^gksu
gksu - graphical frontend to su
gksu-polkit - command line utility to run programs as root

2. Search using a filename contained in the package: apt-file search

Sometimes you can know the name of a file, but not know the name of the package. To use apt-file search, you need to install and update apt-file. (as root: # sudo apt-get -y install apt-file && apt-file update)

$ apt-file search .zshrc | head -3
zsh: /etc/zsh/newuser.zshrc.recommended
zsh: /usr/share/doc/zsh/examples/carstenh.zshrc.gz
zsh: /usr/share/doc/zsh/examples/old/jhm.zshrc.gz

3. List all the files inside a package with: apt-file list

Sometimes you need to see all the files inside a package.

$ apt-file list zsh
zsh: /bin/zsh4
zsh: /etc/zsh/newuser.zshrc.recommended
zsh: /etc/zsh/zlogin
zsh: /etc/zsh/zlogout

4. Find out information about a package with: apt-cache show and apt-cache showpkg

apt-cache show will display the basic information, while apt-cache showpkg will display more info than apt-cache show:

$ apt-cache show freesweep
Package: freesweep
Priority: optional
Section: universe/games
Installed-Size: 176
Maintainer: Ubuntu MOTU Developers

$ apt-cache showpkg freesweep
Package: freesweep
0.90-2 (/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_oneiric_universe_binary-amd64_Packages)
Description Language: en
File: /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_oneiric_universe_i18n_Translation-en

5. List all the package’s dependencies: apt-cache depends

$ apt-cache depends zsh
Depends: libc6
Depends: libcap2
Depends: libtinfo5
Suggests: zsh-doc
Recommends: libc6
Recommends: libncursesw5
Recommends: libpcre3
Conflicts: zsh:i386

6. Downloading the package’s .deb source with apt-get download

I think this is usefull if you want to keep a backup of an older version of the application (to install it if you don’t like the new one).

$ apt-get download transmission
$ ls transmission*

7. Install a package with apt-get install

apt-get first downloads the package and than installs in (running dpkg in bg).

$ sudo apt-get -y install nmap
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
Unpacking nmap (from .../nmap_5.21-1.1_amd64.deb) ...
Processing triggers for man-db ...
Setting up nmap (5.21-1.1) ...

The -y option is usefull if you want to script an apt-get install, because it performs the installation without asking you if you are sure about it.

To update the packagelist use: sudo apt-get install update and to upgrade the system use sudo apt-get install upgrade.

8. Removing/Uninstalling a package with: apt-get remove and apt-get purge

apt-get remove will uninstall the application without removing the configuration files. apt-get purge will delete the application and the configuration files.
$ sudo apt-get -y purge freesweep
Reading package lists... Done
Building dependency tree
Removing freesweep ...
Purging configuration files for freesweep ...
Processing triggers for man-db ...

9. Reinstalling a package with apt-get:

$ apt-get install --reinstall nmap

Verify if a package is installed or not with dpkg -l:

$ dpkg -l | grep freesweep | head -1
ii vim 2:7.3.154+hg~74503f6ee649-2ubuntu3.1 Vi IMproved - enhanced vi editor

If ii is displayed, the application is installed.

Scroll to Top