skip navigation

www.Hilands.com


Content:: apt

Advanced Packaging Tool (apt)
Last Modified: 2014-05-07

Advanced Packaging Tool (APT) is the tool used by Debian based operating systems to install applications. Even the minimal installation of the Debian operating system will have APT installed. There are fancier tools like aptitude which may supply an easier interface to use.
APT uses repositories to supply packages that can easily be installed on a system. The benefit of a repository is one similar to the "App store" for an iPhone, or the Android Market where a general idea of "safe files" located in one central location. These repositories contain enough applications or programs to create servers, desktops, workstations, generally anything you need a computer to be.

Other Linux distributions may use other package managers such as: YUM, APT, PACMAN, Portage/Emerge.

Table of Contents
Configuring apt


The main configuration file for apt is the sources.list which contain information on the locations where apt will search for packages. # nano /etc/apt/sources.list
# deb cdrom:[Debian GNU/Linux 5.0.3 _Lenny_ - Official i386 NETINST Binary-1 20090906-12:06]/ lenny main_
deb http://ftp.us.debian.org/debian/lenny main
deb-src http://ftp.us.debian.org/debian/ lenny main

deb http://security.debian.org/ lenny/updates main
deb-src http://security.debian.org/ lenny/updates main

deb http://volatile.debian.org/debian-volatile lenny/volatile main
deb-src http://volatile.debian.org/debian-volatile lenny/volatile main

The sources.list should be auto generated upon installation.
How to populate the sources.list
You can get a list of the mirrors from http://www.debian.org/mirror/list
Lets start examine the mirror. Digging down into the files we can find the main distributions and version folder dists/lenny.
http://ftp.us.debian.org/debian/dists/lenny/
In here we will find "contrib/", "main/", and "non-free". We will mainly stick to the main distribution files
Going into the main folder you will find folders labeled for the computer system architecture. Most of us will be using the i386 for our standard every day computing systems.
http://ftp.us.debian.org/debian/dists/lenny/main/binary-i386/
Inside this folder we'll find Packages.bz2 and Packages.gz. These two files will contain the list of packages available. If we point our apt sources.list to this location apt can read the packages file to locate the files in the distribution we are looking at.

Editing the sources file we can add the following :
deb http://ftp.us.debian.org/debian/ lenny main
This will tell apt to use the us ftp mirror and go into the lenny and main sections digging us into http://ftp.us.debian.org/debian//debian/dists/lenny/main
The netselect-apt program
The netselect-apt tool is used to find the fastest mirror near you. This will automatically populate the sources list. We can install netselect-apt with apt-get # apt-get install netselect-apt We can run the netselect-apt by typing # netselect-apt stable Netselect will get its list from http://www.debian.org/mirror/mirrors_full
Basic apt commands
After changing the sources.list file apt needs to know to check the file for updates. We can do with with the following command.
# apt-get update
To view or find packages we can install
# apt-cache search <package name>
Uninstall package and installation
# apt-get remove <package name>
Get rid of package, installation and installation files.
# apt-get --purge remove <package name>
To clear dependent packages
# apt-get autoremove
If packages are installed properly make sure they are removed and reinstalled.
e.g. the file won't install the configuration after an uninstall
# dpkg --purge <package name>
# apt-get --reinstall install <package name>
Upgrade the files listed in apt.
# apt-get upgrade
Upgrade a distribution
# apt-get dist-upgrade
Using apt
Finding a the right package can be hard, reading error messages and figuring out what packages need to be installed. You can search the repository with apt search features. After updating a list of packages will be stored on your local machine in the cache. # apt-cache search <package name>
One of my favorite programs is less. Its similar to the more program which many are familiar with even windows users. Running a command and piping the output through more will allow you to see the output one page at a time. Less is similar to the more program but when you pipe the output through less you will be able to scroll up and down with the arrow keys go to the begining and end of the output with < and > keys. To exit less you can hit the q key.
To find the less program with apt-cache search we can pipe the output through grep # apt-cache search less | grep "less -"
You should see a short list and in the list
less - Pager program similar to more
To install less we run # apt-get install less
Now we can pipe the output of our apt-cache search through less # apt-cache search <package name> | less
Where apt files are stored
Location of deb packages :
/var/cache/apt/archives
The files in the archives should all be debian packages. To retrieve a list of packages in the archive you can run # ls /var/cache/apt/archives
Getting Package Information
You can use apt-cache show to get information including versions, sizes, and other information from a package.

# apt-cache show less
Package: less
Version: 444-4
Installed-Size: 286
Maintainer: Anibal Monsalve Salazar <anibal@debian.org>
Architecture: amd64
Depends: libc6 (>= 2.11), libtinfo5, debianutils (>= 1.8)
Description-en: pager program similar to more
 This package provides "less", a file pager (that is, a memory-efficient
 utility for displaying text one screenful at a time). Less has many
 more features than the basic pager "more". As part of the GNU project,
 it is widely regarded as the standard pager on UNIX-derived systems.
 .
 Also provided are "lessecho", a simple utility for ensuring arguments
 with spaces are correctly quoted; "lesskey", a tool for modifying the
 standard (vi-like) keybindings; and "lesspipe", a filter for specific
 types of input, such as .doc or .txt.gz files.
Homepage: http://www.greenwoodsoftware.com/less/
Description-md5: a2c2d2eff1fb9762b71faf7540cf8dce
Tag: implemented-in::c, interface::text-mode, role::program, scope::utility,
 uitoolkit::ncurses, use::viewing, works-with::text
Section: text
Priority: standard
Filename: pool/main/l/less/less_444-4_amd64.deb
Size: 134872
MD5sum: 05e948cf7707a3da8c4381e1ad501489
SHA1: 7e9294d11d24df75ba5338a003b2a0bb608522ac
SHA256: b1383dd98c5b798ceb827e64009429c729120ec25132935885a2ffb56ebaac9e
Using apt-file to list the contents of an archive
Apt file is an additional program that does not come with a basic installation of debian. To install it use apt-get. # apt-get install apt-file
Similar to apt-get apt-file needs to be updated # apt-file update
The update is fairly large and may take some time to download depending on your connection.
Downloading complete file http://ftp.us.debian.org/debian/dists/wheezy/main/Contents-amd64.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
 35 20.4M   35 7536k    0     0   359k      0  0:00:58  0:00:20  0:00:38  475k
After you have updated the apt-file data you can get information about a package. # apt-file list less This will find everything with the keyword less in the package. We can use grep to assist with the information displayed. # apt-file list less |grep ^less
less: /bin/less
less: /bin/lessecho
less: /bin/lessfile
less: /bin/lesskey
less: /bin/lesspipe
less: /usr/bin/less
less: /usr/bin/lessecho
less: /usr/bin/lessfile
less: /usr/bin/lesskey
less: /usr/bin/lesspipe
less: /usr/lib/mime/packages/less
less: /usr/share/doc/less/LESSOPEN
less: /usr/share/doc/less/README.Debian
less: /usr/share/doc/less/changelog.Debian.gz
less: /usr/share/doc/less/changelog.gz
less: /usr/share/doc/less/copyright
less: /usr/share/man/man1/less.1.gz
less: /usr/share/man/man1/lessecho.1.gz
less: /usr/share/man/man1/lessfile.1.gz
less: /usr/share/man/man1/lesskey.1.gz
less: /usr/share/man/man1/lesspipe.1.gz
.....
References