Knowledgebase
Search:     Advanced search
Browse by category:
Glossary | Contact Us

Apt Commands, Resources, & Finding Binary Packages for Linux

Views: 397
Votes: 0
Posted: 24 Sep, 2007
by: Saunders T.
Updated: 22 Jan, 2008
by: Saunders T.
In The Beginning, There Was Apt...
------------------------------------------------------------

   Actually technically in the beginning, there was RedHat Package Manager. But this article isn't about RPM's, is it?
Ok, Well to be serious, RPM's are just binary packages. Like dpkg's. But Apt, well Apt is something more. Apt is similar to a Windows MSI file if you are familiar with those. It cache's a list of servers called repositories that maintain large amounts of software. It installs, and is capable of updating, software automatically on demand.

Apt is a shell based utility, You configure the servers it is to use by editing the sources.list file (/etc/apt/sources.list) I have another article here that gives some example repositories and a little explanation on the meanings of their settings.

There are a number of commands to manipulate Apt directly from your command line. As well as a rather large list of options for each command, I will list some of your most basics and useful here...

  Apt-Cdrom
-------------------------

  #apt-cdrom add
apt-cdrom is used to add new CD/DVDs to Apt's list of available sources. apt-cdrom takes care of determining the structure of the disc as well as correcting for several possible mis-burns and verifying the index files. It is necessary to use apt-cdrom to add CDs to the APT system, it cannot be done by hand. Furthermore each disk in a multi-cd set must be inserted and scanned separately to account for possible mis-burns. To my knowledge, you may just delete a cd-rom from the sources.list file if you wish to remove it. I will test this theory at some point and update.



  Apt-Get
------------------

  #apt-get clean
clean clears out the local repository of retrieved package files. Good idea when updating, esp. if you have removed repositories from your sources.list

  #apt-get update
Re-reads the sources.list, connects to each server and downloads updated indexing files to the cache.

  #apt-get install Package_Name
install is followed by one or more packages desired for installation. Each package is a package name, not a fully qualified filename (For instance, under Debian, libc6 would be the argument provided, not libc6_1.9.6-2.deb) All packages required by the package(s) specified for installation will also be retrieved and installed. According to the man page: "If a hyphen is appended to the package name (with no intervening space), the identified package will be removed if it is installed. Similarly a plus sign can be used to designate a package to install. These latter features may be used to override decisions made by apt-get's conflict resolution system." Not sure how that works, Will have to play with it, but sounded worthy of mentioning.

A specific version of a package can be selected for installation by following the package name with an equals and the version of the package to select. This will cause that version to be located and selected for install. Alternatively a specific distribution can be selected by following the package name with a slash and the version of the distribution or the Archive name (stable, testing, unstable). Both of the version selection mechanisms can downgrade packages and must be used with care.

  #apt-get remove Package_Name
remove is identical to install except that packages are removed instead of installed. If a plus sign is appended to the package name (with no intervening space), the identified package will be installed instead of removed.

  #apt-get upgrade
The Man Page states as follows: "upgrade is used to install the newest versions of all packages currently installed on the system. Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version." This makes me wonder two things 1)Can you use this command to upgrade a specific package while leaving the others alone? (e.g. apt-get upgrade Package_Name) 2) is just a general concern about the safety of running a mass upgrade like that, Things seem to not work when you do that. I take the approach that if it isn't broken don't fix it.



  Apt-Key
-------------------

  #apt-key add File_Name
As I understand it. Apt Communications are transfered over a secure encrypted line, this is ideal to prevent tampering. With this being the case, sometimes you must add a Public Key to your Keyring this way apt can communicate with the repository. This is done by downloading the servers Public Key file (in what little experience I have had, this is an asc file) and running the apt-key command



  Apt-Cache
-----------------------

apt-cache performs a variety of operations on APT's package cache. apt-cache does not manipulate the state of the system but does provide operations to search and generate interesting output from the package metadata.

  #apt-cache search Keyword
search performs a full text search on all available package lists for the keyword pattern given. It searches the package names and the descriptions for an occurrence of the regular expression and prints out the package name and the short description. If --full is given then output identical to show is produced for each matched package, and if --names-only is given then the long description is not searched, only the package name is.

  #apt-cache showpkg Package_Name
showpkg displays information about the packages listed on the command line. Remaining arguments are package names. The available versions and reverse dependencies of each package listed are listed, as well as forward dependencies for each version. Forward (normal) dependencies are those packages upon which the package in question depends; reverse dependencies are those packages that depend upon the package in question. Thus, forward dependencies must be satisfied for a package, but reverse dependencies need not be.

This information can be extremely useful. Had I known this previously, I could have saved myself many reinstalls. The most interesting to me here is the reverse dependencies. The packages that depend upon this one. This is useful because before removing a package, Apt will remove all packages that depend upon it. So for example, when we attempted to remove and reinstall dpkg, had I run one of these I would have found that Apt itself depends upon dpkg, and so no dpkg, no apt to reinstall dpkg. A program that can uninstall itself is impressive.. Also when wishing to reinstall apt-key, I again would have seen that apt itself depends upon apt-keys presence. and though I recovered from that one, it wasn't pretty either...

  #apt-cache rdepends Package_Name -or- #apt-cache depends Package_Name
Pretty self explanatory. Commands to get the specific information rdepeds for recursive dependencies, and depends for dependencies of

  #apt-cache pkgnames Keyword
The man page describes this command as: "This command prints the name of each package in the system. The optional argument is a prefix match to filter the name list. The output is suitable for use in a shell tab complete function and the output is generated extremely quickly. This command is best used with the --generate option." This makes me wonder because I have been looking for the command that will tell me what packages by a given name are currently installed on a system. The way the man reads, this seems like it, But my test with the command weren't quite what I expected. I think I'm gonna post on a forum and ask about the mater. I'll update when I find out.


----

There are also programs for managing apt.

  Aptitude
--------------------

A command line driven program. Generally easier to use than remembering all the stuff up there. ^^
Isn't installed automatically but can be installed with apt.

      #apt-get install aptitude
     
Then just run the command #aptitude from your CLi or Shell, the --help trigger will give you a list of options. I'm not extremely familiar with the various options it contains, so I will update this section as I gain experience.


  Adept
---------------

Now Adept is the schiznit, It's a complete GUI for Apt. Has search box, tells you in a nice graph the packages available, what is and isn't installed and/or upgradeable and, something I like is when you "show details" on a installed package, the details has a nice "Installed Files" tab which can be useful in hunting down stuff post install.

The only thing I have to say negatively about adept is that, although it is designed to handle such things, I have experienced issues sporadically with it's ability to allow you to interface with the installation in progress. so it will sometimes hang or fail to install because the package requires input from you, configuration questions or agreeing to licensing terms or the like. If it fails you can try to run the command from a shell using apt or aptitude and see, sometimes it's a simple thing. If you are doing something big and it is instructed to give you menu to make a selection or to input a configuration, it will often hang and you would be forced to kill adept, thus interrupting the install and causing apt to blow an error every time you attempt to use it. The error is something about incomplete or uncommitted changes and tells you to attempt a command, which tends to clear it up. I want to say the command it suggest is #dpkg -a --configure but that is purely from my memory at this point. According to the help file that would tell it to configure pending packages. Again next time I see the error I will update with the exact command.

----

Last but not least, dpkg itself has a command that will allow you to search for packages. Although not used as often as Apt, dpkg has a -list command.

      #dpkg -l Keyword
     


 This information is here to serve primarily as notes for Kinetic Bands internal uses, they are web accessible only in hopes that the information contained may be useful to others, I find the Man2HTML project very useful for accessing man page information both away from a linux shell, and also for general research. The information contained in this article was obtained partly from their resource. Follow the link below for more information.

 http://olympus.het.brown.edu/cgi-bin/man/man2html
Others in this Category
document Apt Get Error While Updating: Could Not Connect to localhost:4001 (111 connection refused)
document Complete Apt Repository Sources.list



RSS