AptGetHowto

Revision 4 as of 2005-08-15 02:55:11

Clear message

Package management with apt

attachment:IconsPage/IconApt.png

Intro

In the beginning there was the .tar.gz. Users had to compile each program that they wanted to use on their GNU/Linux systems. When Debian was created, it was deemed necessary that the system include a method of managing the packages installed on the machine. The name dpkg was given to this system. Thus the famous 'package' first came into being on GNU/Linux, a while before Red Hat decided to create their own 'rpm' system.

A new dilemma quickly took hold of the minds of the makers of GNU/Linux. They needed a rapid, practical, and efficient way to install packages that would manage dependencies automatically and take care of their configuration files while upgrading. Here again, Debian led the way and gave birth to APT, the Advanced Packaging Tool, which has since been ported by Conectiva for use with rpm and has been adopted by some other distributions.

  • From Debian APT HOWTO

Commands

All these commands require sudo!

  • apt-get update - Run this after changing /etc/apt/sources.list or /etc/apt/preferences. You also must run it periodically to make sure your source list is up-to-date.

  • apt-get install packagename - installs a new package (but see aptitude, below)

  • apt-get remove packagename - removes a installed package (configfiles remain)

  • apt-get --purge remove packagename - removes a installed package (configfiles will also be removed)

  • apt-get upgrade - upgrades all installed packages

  • apt-get dist-upgrade - upgrades the entire system to a newer release

  • apt-cache search string - Searches for string in the list of known packages

  • dpkg -l package-name-pattern - List packages matching pattern

  • aptitude - Curses viewer of packages installed or available. Aptitude can be used from the command-line in a similar way to apt-get, but only for some commands - install and remove being the most common. However, because aptitude keeps track of more information than apt-get does, it can be considered better at install and remove operations.

  • apt-cache showpkg pkgs - Show information about packages.

  • apt-cache dumpavail - Prints out an available list.

  • apt-cache show pkgs - Displays package records, similar to dpkg --print-avail.

  • apt-cache pkgnames - Fast listing of every package in the system.

  • dpkg -S file - Which installed package owns the file?

  • dpkg -L package - List files in the package.

  • apt-file search filename - Search for a package (need not be installed) containing files including the string. apt-file is a package of its own, which you may have to apt-get install first, then run apt-file update. If apt-file search filename shows you too much, try apt-file search filename | grep -w filename (which shows you only the files that contain filename as a whole word) or variants like apt-file search filename | grep /bin/ only files located in directories like /bin or /usr/bin, useful if you're looking for a particular executable).

* apt-get autoclean - Run this periodically to clean out .deb archives from packages which are no longer installed on the system. You can regain lots of disk space that way. If you're really desperate for disk space, apt-get clean is more radical, and will remove .deb files even for packages currently installed. But most of the time you probably don't need the .debs any more, so it might be worth it if you're strapped for megabytes.

Typical use case

I want to feel the wind in my hair, I want the adrenaline of speed. So let install a racing game. But what are available racing games ?

apt-cache search racing game

It gives me a lot of answer. I see a game named "torcs". What is this game ?

apt-cache show torcs

Hmmm... it seems intersting. But is this game not already installed on my computer ? And what is the available version ? Is it from Universe or main ?

apt-cache policy torcs

Ok, so now, let's go to install it !

apt-get install torcs

What is the command I must type in the console to launch this game ? In this example, it's straightforward ("torcs"), but it's not always the case. A tricky way of finding the name of the binary is to look what are files installed by the package in "/usr/bin". For games, it's in "/usr/games". For administrative programs, it's in "/usr/sbin".

dpkg -L torcs|grep /usr/games

The first part of the command display all files installed by the package "torcs". (try it) With the second part, we ask to only display lines containing "/usr/games".

Hmmm, that game is gool. Maybe is there some extra tracks ?

apt-cache search torcs

But I'm running out of space. I will delete the apt cache!

apt-get clean

Oh no, my mother asked for removing all games from this computer. But I want to keep all configuration files so I can simply reinstall it later.

apt-get remove torcs

If I want to remove also config files :

apt-get remove --purge torcs

Additional packages

deborphan and debfoster are great for finding orphaned and unneeded packages which can be removed.

Speeding up your work at the command line

The command line is powerful, but typing is slow, so make your commands shorter. You might put this in your *~/.bashrc*

    alias acs='apt-cache search'
    alias agu='sudo apt-get update'
    alias agg='sudo apt-get upgrade'
    alias agd='sudo apt-get dist-upgrade'
    alias agi='sudo apt-get install'
    alias agr='sudo apt-get remove'

But see aptitude, above, for a reason to use "alias agi='sudo aptitude install'"


CategoryDocumentation