The apt-get Package Management Tool

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search

The apt-get command is a powerful command-line tool for performing such functions as installation of new software packages, upgrade of existing software packages, updating of the package list index, and even upgrading the entire linux distribution system on a computer.

The apt-get command is part of APT, or Advanced Packaging Tool. APT was originally designed as a front-end for dpkg to work with Debian's .deb packages. There is no single "apt" program; apt is a collection of tools. Two such programs are apt-get and apt-cache. This document focuses on apt-get.

Some common distributions that use apt-get:

  • Debian
  • Ubuntu / KUbuntu
  • Linux Mint

install software using apt-get

The command to install a package

apt-get install package

apt-get install --only-upgrade <packagename> will not install any new packages

apt-get install <packagename> will upgrade only that single package

You may not know the specific package name for software you wish to install. Say you want to install vnc client viewer but you don't know the name of a package for it. You would open a console as root or use sudo and type:

apt-cache search vnc
apt-cache search vnc|grep viewer

This would return a list of packages available and that refer to the word vnc. Maybe not much different than

apt-cache pkgnames|grep vnc

remove software with apt-get

When you use the command apt-get remove <package> it removes that package from the system.

apt-get remove package

This will remove the core software application but "sometimes" may leave behind some settings files, much like Windows Uninstall leaves files behind on Microsoft Windows - yet not nearly as bad.

apt-get remove --purge package  
apt-get clean

Can be used to clean things up better.

is a particular package installed?

Check if a package is installed or not in DEB based systems. For the example lets check to see if postfix is installed.

dpkg -s postfix

This will show additional information if it (the package) is installed including the version information, size, keys, a description, and more.

Another option is 'dpkg-query'

dpkg-query -l postfix

Output is tab formatted and also includes some information although not as verbose.

show installed packages

This can't be accomplished with the apt-get command. You can revert to dpkg.

dpkg-query -l

or

dpkg -l
dpkg-query -W -f '${status} ${package} ${version}\n' | sed -n 's/^install ok installed //p'
dpkg --get-selections
dpkg --get-selections | sed 's:install$::'

You can make a shell script called 'apt-installed' and put whatever format you like.

What about 'apt-cache'?

apt-cache pkgnames

List the names of all package - more than whats installed, apt-cache creates a repository of information about the packages that are avaiable from your sources list, so this way you can search packages and information about it. It is not a means to show only what is installed.

repositories

Apt stores a list of repositories or software channels in the file.

/etc/apt/sources.list

These are places where software can be obtained from using apt-get. The main repositories are stored in this file, not additional repositories use add with the add-apt-repository command. Do not manually edit sources.list or, if you feel you must, make a backup first before editing.

For example, user wanted to install the tv-maxe app on Ubuntu which is not in the typical Ubuntu repositories. So user added a repository.

add-apt-repository ppa:venerix/pkg
apt-get update

The second command, 'apt-get update' downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies. Since user added a new repository, the command is ran to update the latest package list from that new repository. A new repository is also known as a 'PPA'.

The new repositories user added do not get added to the sources.list file, but instead they go into separate files under

/etc/apt/sources.list.d

And you can use the add-apt-repository command to remove them

apt-add-repository --remove ppa:venerix/pkg

This does not remove the program that was installed, in this case tv-maxe. Now user will not be able to easily update tv-maxe via the 'apt-get install <packagename> will upgrade only that single package.' - since the repository is gone. If user wishes to keep tv-maxe easily updated with new releases, user will have to keep the repository. You can also manually delete the .list files from the /etc/apt/sources.list.d directory. To manually remove the repository venerix/pkg for which tv-maxe was obtained:

rm /etc/apt/sources.list.d/venerix-pkg-precise.list
apt-get update

apt-get update

The command apt-get update downloads the package lists from the repositories and "updates" them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs.

apt-get update

Run this command after changing /etc/apt/sources.list or /etc/apt/preferences - or if you remove any repository from sources.list.d via 'apt-add-repository --remove' command line or manually deleting with the rm command.

Also, run the 'apt-get update' command periodically to make sure your source list is up-to-date. This is the equivalent of "Reload" in Synaptic or "Fetch updates" in Adept.