justlinux.com
Sun, 27-May-2012 11:41:31 GMT

Forum: Registered Users: 76222, Online: 315
nhfs Here you can view your subscribed threads, work with private messages and edit your profile and preferences Registration is free! Calendar Find other members Frequently Asked Questions Search Home Home

Help File Library: Using Apt


Written By: Evil Jeff

One of the reasons that Debian is such a cool and intuitive distribution is because of its packaging system (*.deb). The installation uses a program called apt to download and install programs from cds, nfs, ftp, or http. Because of this, you can install an entirely current system from an old installation cd. The most remarkable thing about apt, however, is that it checks and maintains dependencies for you, so you do not need to go around hunting for libraries that you need before installing your favorite programs. Once you select a program to install, apt will check to see what other software is needed for it to work and then offer you the option of downloading and installing what else is required as well. This Help File should work for Debian, Stormix, and Libranet.

Apt is also used to install new programs and keep your installation up to date with the latest software releases, as well as to upgrade to the next distribution of Debian. There are several front ends to apt, such as aptitude, console-apt, and dselect. In this Help File, I will discuss the basics of how to configure and use apt to upgrade your system, install new software, and upgrade your distribution, using the basic command line form of the program.

First, you must be logged in as root in order to use apt. This is because you are making changes to your system, which a normal user does not have permission to do. Second, you may need to edit apt's configuration in order to download packages. To do this, type cd /etc/apt/ as root, and edit the file sources.list to make sure that the debian ftp/http sites are uncommented. You may want to comment out any cdrom references if you want to use only the most up-to-date software, too. Ftp/http entries in your sources.list file follow this syntax:
deb ftp://ftp.debian.org/debian stable main contrib non-free deb-src
ftp://ftp.debian.org/debian stable main contrib non-free

For the unstable (currently Potato) distribution of Debian, change stable to read unstable. However, before you install any unstable software on a stable system, please read the section Upgrading Your Distribution below.

Another option is to find a maintained list and use that as your sources list. The advantage of this is that this list has a collection of many different sites that contain a wide range of software. The disadvantage is that many of these sites might not be entirely stable. You be the judge of how stable you want your distribution to be.

Once you have your sources.list the way you want it, type this syntax as root:
apt-get update

This causes apt to update its package database by downloading file lists from the sites you have listed. Before you install new packages or upgrade, it is normally advisable to perform an apt-get update to make sure you are getting the most current packages.

Upgrading

Once this has completed, you can then use apt-get to upgrade your system. The syntax for this is, simply enough:
apt-get upgrade

You will be given an estimate of how much must be downloaded in order to upgrade all installed packages to the most current release, as well as how much more space will be used or how much will be freed, and a prompt on whether or not to continue.

Depending on what exactly was upgraded, you might be given some questions about whether or not to also upgrade certain configuration files (to which a safe answer is no) as well as some possible pre-configuration questions. I won't go into these because there are over 6,500 possibilites for pre-configuration questions.

Installing Software

Installing new sotware is as easy as upgrading. Once you have apt-get updated (to make sure you get the current release), you simply type this as root:
apt-get install packagename

You can either guess at the package name (ie apt-get install links, or apt-get install abiword) or you can search your database for one word to see if you can find it. To do this, you use:
apt-cache search packagename

Some front ends to apt will have a visual/searchable list of packages in your current database, but that's another Help File. Once again, after you enter the command, apt will check for any dependencies you need filled to make the program work and will offer to install those for you as well. This method will also preconfigure the packages before installing them for you.

Likewise, you can uninstall software from your system by typing:
apt-get remove packagename

Upgrading Your Distribution

Be warned! Upgrading to the unstable version of Debian means exactly that--it will be unstable. These programs are not fully tested by debian yet, so use this at your own risk.

To upgrade to the newest distribution, you must edit your sources.list file (in /etc/apt) to change all references to stable to unstable, or add copies of the stable entries with the modifications. Run an apt-get update to update your list, and then type this:
apt-get dist-upgrade

Depending on the size of your original installation, this could take forever. But if you are going to use the unstable trees, you should do this before installing any singular software packages in order to maintain all of your dependencies correctly. Simply installing the newest version of one program might require too many other upgrades with more and more dependencies to keep updating, and apt will give you an error saying something like sorry, package has no installation candidate or sorry, broken packages.

Troubleshooting

This can be kind of complicated. If there are problems in the debian tree, your dependencies might become so corrupted that you will have to force or manually install packages to make them work.

The first step is to type:
apt-get -f install

This gives apt permission to force file installation and overwrite old files in order to install the problematic packages. This should be a safe bet.

If this doesn't work, you may need to rely on the back end of apt, called dpkg. You use this syntax to install a .deb package with dpkg:
dpkg -i packagename.deb

However, this may not work. There are a whole slew of options with dpkg for forcing packages to install. To view them, type:
dpkg --force-help

An example of forcing a file would be (using the overwrite option):
dpkg -i --force-overwrite packagename.deb

Beware though that this can cause unmet dependencies in your system, or overwrite files that may be needed by other programs. If you know the package that is actually causing the problem and you can't get apt-get to install or remove it itself, you can use dpkg to purge the package from your "pending" list, freeing apt-get to correctly configure and preserve your dependencies. The syntax for this is:
apt-get clean
dpkg --purge packagename

Cleaning it up

To clean up downloaded packages that are already installed, type:
apt-get autoclean
or
apt-get clean

Autoclean will erase old packages, clean will erase all downloaded packages. Hope this helps.