Sunday, May 17, 2015

Basic Commands of APT-GET and APT-CACHE for Package Management

APT-GET and APT-CACHE Tutorial - Now we talk about linux commands again. Using CLI (Command Line Interface) in your terminal is really important things you should to learn. Why make it important? This is the basic for learn Linux.

It's practice, simple and efficient ways to install/run/configure applications. The others things make this important is not all of Linux tools has GUI (Graphical User Interface).

I made this article to tell and explain for beginners about apt-get and apt-cache commands for manage the package in Linux.

1. What's APT Mean

ap-get and apt-cache for package management

Start from the description, APT is acronym for Advanced Packaging Tool, the command-line tool for working with APT software packages. It is an evolution of the Debian .deb software packaging system which efficient, rapid, and of course practical way to install packages on our system. Dependencies are managed automatically, configuration files are maintained, and upgrades and downgrades are handled carefully to ensure system stability.

2. How to use APT-GET Commands

Apt-get operates on a database of known, available software. It performs installations, package searches, and many other operations by referencing this database. Due to this fact, before beginning any packaging operations with apt-get, we need to ensure that our local copy of the database is up-to-date. Here some list of apt-get command which important for you to :

2.1 apt-get update

This command should always be performed before an upgrade or dist-upgrade. The indexes are fetched from the location(s) specified in /etc/apt/sources.list. It means re-synchronizes the local index of packages files, updating information about new and updated packages that are available. We'll see a list of servers we are retrieving information from. y run apt-get update, our database should be up-to-date.

2.2 apt-get upgrade

Installs the newest versions of all packages currently installed on the system, using the sources in /etc/apt/sources.list. If a package is currently installed and a new version is available, it is retrieved and upgraded. Under no circumstances are installed packages removed, or packages not already installed retrieved.

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. An update should always be performed first so that apt-get knows which new versions of packages are available.

2.3 apt-get dist-upgrade

in addition to performing the function of upgrade, we can use the "dist-upgrade" argument, which attempts intelligent dependency resolution for new packages and will upgrade essential programs at the expense of less important ones. The dist-upgrade command may therefore remove some packages.

2.4 apt-get dselect-upgrade

Used in conjunction with the traditional Debian packaging front-end, dselect. dselect-upgrade follows the changes made by dselect to the Status field of available packages, and performs the actions necessary to achieve that state (for instance, the removal of old and the installation of new packages).

2.5 apt-get install

If you know the name of the package you wish to install, so the packages are specified by their package name, not a fully qualified filename. An important things to understand that apt-get install is not only installs the requested software, but also any software needed to install or run it. This is the example :

apt-get install gimp

That command will install gimp manipulation pictures editor. How about install multiple packages? Yes we can! We also can install multiple package at the same time by one hit  :

apt-get install gimp moc moc-ffmpeg-plugin

You can see those command, we install 3 packages at the same time by one hit. In this case we install gimp, moc, and moc-ffmpeg-plugin. Moc means Music On Console which make we can play our favorites music in terminal.

2.6 apt-get remove

How to remove appication or packge in linux? This command will answer this question. Using apt-get remove is one of some ways that we can remove package or application.

apt-get remove virtualbox-4.3

This command removes the package, but keeps the configuration files in case you install the package again later. So, your settings will remain intact, even though the program is not installed. 

2.7 apt-get purge

We also can remove package by apt-get purge. This'is the command looks :

apt-get purge virtualbox-4.3

But, it's different things from apt-get remove which still keeps the configuration files. By using apt-get purge we will completely uninstalls the package and removes any configuration files associated with the package. So, if we don't want to keep our configurations, we can use apt-get purge.

2.8 apt-get autoremove

Autoremove is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed. In another words its mean to remove any packages that were installed automatically to support another program, that are no longer needed.

2.9 apt-get clean

It will clears out the local repository of retrieved package files, removes everything but lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/. When APT is used as a select method, clean is run automatically. This will clean up disk space.

2.1.1 apt-get check

Is a diagnostic tool. It updates the package cache and checks for broken dependencies.

3. How to use APT-CACHE Commands

While "apt-get" is used to upgrade, install, and remove packages, "apt-cache" is used to query the package database for package information. You can use the following command to search for a package that suits your needs. Note that apt-cache doesn't usually require administrative privileges:

3.1 Print List All Available Packages

To list all the available packages, type and run this command in your terminal :

# apt-cache pkgnames
automoc - automatic moc for Qt 4 packages
google-mock - Google's framework for writing and using C++ mock classes
libdbd-mock-perl - Mock database driver for testing
libeasymock-java - Java library to generate Mock Objects for given interfaces
libeasymock-java-doc - Java library to generate Mock Objects for given interfaces (documentation)
libflexmock-ruby - Transitional package for ruby-flexmock
libflexmock-ruby1.8 - Transitional package for ruby-flexmock
libflexmock-ruby1.9.1 - Transitional package for ruby-flexmock
libghc-data-memocombinators-dev - Combinators for building memo tables library
libghc-data-memocombinators-doc - Combinators for building memo tables library; documentation

3.2 Find Out Package Name and Description of Software

To show package name and desciptions before installing, we must add little flag. By set 'search' as flag with apt-cache will print list of matched packages with short descriptions. If you would like to find out description of package 'netcat', so it would be like this :

# apt-cache search netcat
cryptcat - A lightweight version netcat extended with twofish encryption
dbd - Netcat clone with encryption
golismero - Web application mapper
ncat-w32 - Netcat for the 21st century
netcat - TCP/IP swiss army knife -- transitional package
netcat-openbsd - TCP/IP swiss army knife
netcat-traditional - TCP/IP swiss army knife
netcat6 - TCP/IP swiss army knife with IPv6 support
netrw - netcat like tool with nice features to transport files over network
sbd - Secure backdoor for linux and windows
webhandler - Bash simulator to control a server using PHP system functions

Then to find and list down all the packages starting with ‘netcat‘, you could use this command :

# apt-cache pkgnames netcat

3.3 Check statistics of Cache

Flag ‘stats‘ will show you overall statistics about the cache. For example, the command below will display Total package names is the number of packages have found in the cache :

# apt-cache stats
Total package names: 47861 (957 k)
Total package structures: 47861 (2,297 k)
  Normal packages: 36399
  Pure virtual packages: 455
  Single virtual packages: 4260
  Mixed virtual packages: 1001
  Missing: 5746
Total distinct versions: 38348 (2,454 k)
Total distinct descriptions: 37412 (898 k)
Total dependencies: 227672 (6,375 k)
Total ver/file relations: 41651 (666 k)
Total Desc/File relations: 37412 (599 k)
Total Provides mappings: 7725 (154 k)
Total globbed strings: 157 (1,630 )
Total dependency version space: 927 k
Total slack space: 50.1 k
Total space accounted for: 12.0 M

4. Use APT-GET Commands With Options

Next, we'll talk about how to use apt-get commands with options. There's some example in this point you can learn.

4.1 Install Packages without Upgrade

Do not upgrade packages; when used in conjunction with install, no-upgrade will prevent packages on the command line from being upgraded if they are already installed.

# apt-get install <packagename> --no-upgrade</packagename>

4.2 Download a Package Without Installing

We can only download any package without installing by add ‘download‘ option. For example, the following command will only download ‘virtualbox‘ package to current working directory.

# apt-get download virtualbox
Get:1 Downloading virtualbox 4.3.20-dfsg-1~kali1 [16.0 MB]
1% [1 virtualbox 222 kB/16.0 MB 1%]                          27.6 kB/s 9min 33s

I have some Linux commands + Open source graphicaal software Inkscape posts that maybe help you to learn Linux :
  1. Basic Linux Commands Most Frequently Used
  2. 26 Useful Linux Terminal Keyboard Shortcuts You Must Know
  3. Inkscape 0.91 Advance Keyboard Shortcuts

So that's all I can write about Basic Commands of APT-GET and APT-CACHE for Package Management. Hope you've enjoyed reading this tutorial as much I’ve enjoyed writing it. Please comment with feedback to support us. Thanks for visit.

Related Post

2 Responses to "Basic Commands of APT-GET and APT-CACHE for Package Management"