Translate

Friday, February 22, 2013

Debian/Linux:Advanced Packaging Tool(APT)


APT is the Advanced Packaging Tool and provides the apt-get program.APT provides an efficient way to retrieve and install packages from multiple sources using the command line.

In contrast to dpkg (another debian based package management tool),apt-get does not understand .deb files,it works with the package's proper name and can only install .deb archives from a source specified in '/etc/apt/sources.list'.A screenshot for the same is shown below.



Note: apt-get will call dpkg directly after downloading the .deb archives from the configured sources.
Some of the common usages of the apt-get program is illustrated below.

Update

To update the list of packages known by your system,issue the following command on the terminal
apt-get update


Upgrade

To upgrade the installed packages(for which an upgradable version is available in the repository) on your system 
apt-get upgrade


 Install a package

To install a package and all its dependencies,issue this command on the terminal
apt-get install

For example,to install the 'apache' webserver and all its dependencies
apt-get install apache2

 

Remove a package

To remove a package from your system
apt-get remove

For example,to remove the 'gedit' program from your system
apt-get remove gedit
Note : The above command will just remove the gedit program.It will not remove the configuration files related to the gedit program.

To completely remove the gedit package along with the configuration files
apt-get --purge remove gedit

 

Saving your valuable disk space

Each time you install an application using apt-get,the corresponding deb package is downloaded and stored in a location on the hard disk,usually the directory '/var/cache/apt/archives'.

The following command will remove all the archives and free up hard disk space
apt-get clean

To delete only those packages in the cache which are found useless or partially complete,use this command
apt-get autoclean

The 'apt-cache' tool 

Another tool in the APT tool suite is apt-cache.
The apt-cache tool can be used to search for and find packages,and the best thing is that it supports use of regular expressions.The uses of this tool is illustrated below.

To find all packages that contain the word 'editor',use this command from the console
apt-cache search editor
The screenshot for the same is included below.


 


To print detailed information about a package,the syntax is-
apt-cache show


To display the packages that a given package depends on,the syntax is-
apt-cache depends

apt-cache depends apache2 will list all the packages that apache2 depends on.Simple,isn't it.



To print the detailed info of the versions available for a package and the packages that reversely depends on it,use this command
apt-cache showpkg




To get statistics of the packages available in the repositories,use this command
apt-cache stats



The history of package installation/removal/update using apt can be viewed in the history.log file (look in the directory /var/log/apt)
 
This completes the tutorial on APT.Stay tuned for more tutorials on package management on Unix/Linux based systems.Cheers!!!

 

No comments: