Usage of APT Package Management Utility in Debian GNU/Linux Systems

apt-get is the command-line tool for handling packages, and may be considered the user's "back-end" to other tools using the APT library.
Several "front-end" interfaces exist, such as dselect, aptitude, synaptic and wajig.

If you are a debian user, you are probably aware of the APT package handling utility. This article will help you gain more about the usage of apt-get utility.

1. To install a particular package

install is followed by one or more packages desired for installation or upgrading. Each package is a package name, not a fully qualified filename (for example, in a Debian GNU/Linux system, libc6 would be the argument provided, not libc6_1.9.6-2.deb)

Usage:

Syntax: apt-get install <package_name>

root@1J52VQ1:~# apt-get install putty

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
putty-tools
Suggested packages:
putty-doc
The following NEW packages will be installed:
putty putty-tools

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.

2. To remove a particular installed package

remove is identical to install except that packages are removed instead of installed. Note the removing a package leaves its configuration files in system.

Usage:

Syntax: apt-get remove <package_name>
root@1J52VQ1:~# apt-get remove putty

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
putty-tools
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
putty

Installing a package with remove:

If a plus sign is appended to the package name (with no intervening space), the identified package will be installed instead of removed.

3. Remove the obsolete packages

autoremove is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed.

Usage:

Syntax: apt-get autoremove

root@1J52VQ1:~# apt-get autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
putty-tools

4. To purge an installed package

purge is identical to remove except that packages are removed and purged, i.e. the configuration files are removed along with the package.

Usage:

Syntax: apt-get purge <package_name>
root@1J52VQ1:~# apt-get purge putty

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
putty*

5. To refresh the available updates

update is used to resynchronize the package index files from their sources. The indexes of available packages are fetched from the location(s) specified in /etc/apt/sources.list.

Usage:

Syntax: apt-get update
root@1J52VQ1:~# apt-get update

Get:1 http://security.ubuntu.com precise-security Release.gpg [198 B]
Hit http://archive.ubuntu.com precise Release.gpg
Get:2 http://archive.ubuntu.com precise-updates Release.gpg [198 B]
Get:3 http://archive.ubuntu.com precise-proposed Release.gpg [198 B]
Get:4 http://archive.ubuntu.com precise-backports Release.gpg [198 B]
Get:5 http://security.ubuntu.com precise-security Release [49.6 kB]

6. To install the newest version of all packages or upgrade existing packages

upgrade is used to install the newest versions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list.

Usage:

Syntax: apt-get upgrade
root@1J52VQ1:~# apt-get upgrade

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
linux-generic linux-headers-generic linux-headers-generic-lts-raring
linux-headers-lowlatency linux-image-generic linux-image-generic-lts-raring
linux-image-lowlatency linux-lowlatency

7. To search for a particular package

With search, you can search for any package from the apt-cache by providing a search term related to the package.

Usage:

Syntax: apt-cache search  <search_term>
root@1J52VQ1:~# apt-cache search terminal

pterm - PuTTY terminal emulator
ptex2tex - easy generation of (possibly complex) LaTeX environments
putty - Telnet/SSH client for X
pyqonsole - X Window terminal emulation written in Python
python-libssh2 - Python binding for libssh2 library

In case, you want to search more about any particular package:

Usage:

Syntax: apt-cache search <package_name>
root@1J52VQ1:~# apt-cache search putty

libtrilead-putty-extension-java - PuTTY key support for Trilead SSH2 library
libtrilead-putty-extension-java-doc - Documentation for libtrilead-putty-extension-java
pterm - PuTTY terminal emulator
putty - Telnet/SSH client for X
putty-doc - PuTTY HTML documentation
putty-tools - command-line tools for SSH, SCP, and SFTP

8. Query information about a particular package

With show, you can view the description of package fetched from the apt-cache and other relevant information including version, size, dependencies, architecure, section, etc.

Usage:

Syntax: apt-cache show <package_name>
root@1J52VQ1:~# apt-cache show putty

Package: putty
Description-en: Telnet/SSH client for X
This is the Unix port of the popular Windows SSH client, PuTTY. It supports
flexible terminal setup, mid-session reconfiguration using Ctrl-rightclick,
multiple X11 authentication protocols, and various other interesting things
not provided by ssh in an xterm.
Priority: optional
Section: universe/net
Installed-Size: 850
Architecture: amd64
Version: 0.62-6ubuntu0.1

9. Query if a package is already installed or not and check the available version:

With policy, you can view if a particular package is installed on your system or not and it will display the available version as well.

Usage:

Syntax: apt-cache policy <package_name>
root@1J52VQ1# apt-cache policy putty

putty:
Installed: (none)
Candidate: 0.62-6ubuntu0.1
Version table:
0.62-6ubuntu0.1 0
500 http://security.ubuntu.com/ubuntu/ precise-security/universe amd64 Packages
500 http://archive.ubuntu.com/ubuntu/ precise-updates/universe amd64 Packages
0.62-6 0
500 http://archive.ubuntu.com/ubuntu/ precise/universe amd64 Packages

This quote below explains the above output.

package-name:
  Installed: <installed-version>
  Candidate: <version-installed-when-doing-apt-get-upgrade>
  Package-Pin: <version-of-Pin-in-etc-apt-preferences>
  Version table:
 *** <some-version> <minimum-priority-to-consider>
       <priority-of-this-instance> <repository1>
       <priority-of-this-instance> <repository2>
 *** <some-other-version> <minimum-priority-to-consider>
       <priority-of-this-instance> <repository3>
       <priority-of-this-instance> <repository4>

This link here explains a bit more about the above output.

10. Delete the apt-cache completely

clean clears out the local repository of retrieved package files.It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/.

Usage:

Syntax: apt-get clean
root@1J52VQ1:~# apt-get clean

11. Delete the apt-cache partially (remove only the package files that can no longer be downloaded)

Like clean, autoclean clears out the local repository of retrieved package files. The difference is that it only removes package files that can no longer be downloaded, and are largely useless.

Usage:

Syntax: apt-get autoclean
root@1J52VQ1:~# apt-get autoclean
Reading package lists... Done
Building dependency tree
Reading state information... Done

12. Fix the broken packages

This has been a life saver for me a lot of times. You have a package that did not install properly because of some missing dependencies, try using install -f, it fixes the stuff most of the times.

Usage:

Syntax: apt-get install -f
root@1J52VQ1:~# apt-get install -f

Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 264 not upgraded.

13. Download a package

download will download the given binary package into the current directory.

Usage:

Syntax: apt-get download <package_name>
root@1J52VQ1:~# apt-get download putty
Get:1 Downloading putty 0.62-6ubuntu0.1 [338 kB]
Fetched 338 kB in 3s (92.9 kB/s)

Related

linux 8331424902838692006

Post a Comment

emo-but-icon

 

Recent Posts

comments

Join Us

 

Recommended

item