apt Command: Tutorial & Examples
Install, remove, and manage software packages
The apt
command is a package management tool that is used to install, remove, and manage packages on a Debian-based Linux distribution such as Ubuntu. It stands for "Advanced
Package Tool" and is a front-end to the dpkg
package manager.
To use apt
, you must first update the package manager's list of available packages by running the command apt update
. This retrieves a list of packages and their versions that
are available from the repositories specified in the /etc/apt/sources.list
file.
Once the package list has been updated, you can use apt
to install a new package by running apt install package_name
. For example, to install the emacs
text editor, you would
run:
$ apt install emacs
You can also install multiple packages at once by separating their names with a space, like this:
$ apt install emacs htop
You can use apt also to remove a package by running apt remove package_name
. This will remove the package, but it will leave behind any configuration files that the package may
have created. To completely remove a package, including its configuration files, you can use the apt purge command, like this:
$ apt purge package_name
There are many other options and subcommands available with apt
, such as apt search
to search for a package by name, apt show
to display information about a package,
and apt update
to update the package manager's list of available packages. You can view a full list of options by running apt --help
or man apt
in the terminal.
APT pinning
APT pinning is a feature of the Advanced Packaging Tool (APT) system in Linux that allows you to specify preferences for where to install packages from. APT pinning is typically used to specify which repositories (sources of packages) should be used to install packages, and can be used to install packages from specific repositories or to prevent packages from being installed from certain repositories.
One use case for APT pinning is to install packages from the unstable repository in Debian and Ubuntu. The unstable repository contains the latest versions of packages that are not yet considered stable enough for the stable repository. By using APT pinning, you can install packages from the unstable repository while still using the stable repository as the default.
To use APT pinning to install packages from the unstable repository, you will need to do the following:
Add the unstable repository to your APT sources list. Edit the /etc/apt/sources.list file and add a line for the unstable repository. For example:
deb http://deb.debian.org/debian unstable main
Create a file in the /etc/apt/preferences.d/ directory to specify your pinning preferences. For example, you might create a file called unstable.pref with the following content:
Package: *
Pin: release a=unstable
Pin-Priority: 500
This will specify that the unstable repository should be used as a preference for installing packages, but that other repositories should be used as a fallback if a package is not available in the unstable repository.
Update your package list and install the desired package. Run the following commands to update your package list and install a package from the unstable repository:
$ sudo apt update
$ sudo apt install -t unstable package-name
Replace package-name with the name of the package that you want to install.
Note that installing packages from the unstable repository can be risky, as the packages have not yet been fully tested and may contain bugs or other issues. It is generally recommended to use the stable repository as the default, and only use the unstable repository for specific packages when necessary.