apt-get - Ubuntu package management system

Ubuntu which is based on Debian Linux, share the same great package management system as Debian such as dpkg, apt, aptitude and synaptic for x-window. In Ubuntu, apt is more like the official package management system at the moment. However, users still have a choice and can freely use whatever package management system they are comfortable with.

In this tutorial, we are going to look closely into the popular apt package management system.

Ubuntu apt package manager

apt means Advanced Package Tool, is a software package manager use by Ubuntu and other Debian-based Linux distributions' users around the world. The apt-get which is apt package handling utility is a command line interface for update, upgrade, install and remove software packages. So, for package management system in Ubuntu, what a user needs is apt-get. Lets take a closer look at apt-get manual page:

NAME
apt-get - APT package handling utility -- command-line interface

SYNOPSIS
apt-get [-hvs] [-o=config string] [-c=file] {[update] | [upgrade] |
[dselect-upgrade] | [install pkg...] | [remove pkg...] |
[purge pkg...] | [source pkg...] | [build-dep pkg...] | [check]
| [clean] | [autoclean] | [autoremove]}

DESCRIPTION
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(8), aptitude,
synaptic, gnome-apt and wajig.

apt-get cannot be used alone without options except for -p or --help. You need to specify what do you want apt-get to do such as update, upgrade, install or remove package. Here are apt-get options that normally used with apt-get:

  • update - 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.
  • upgrade - 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.
  • install - install is followed by one or more packages desired for installation.
    Each package is a package name, not a fully qualified name with a version.
  • remove - remove is identical to install except that packages are removed instead
    of installed.

There are other options available to use with apt-get. The options above are what user normally need to manage software packages in Ubuntu system. You can check apt-get manual page for more options if you need that later. Use the command man apt-get to open apt-get manual page.

How to use Ubuntu apt-get?

Normally, we would use apt-get update command first to synchronize software packages installed in our system with the latest software packages in Ubuntu sources server. Software packages is not being installed. The apt-get update only compare system packages with the latest sources from the server. Because installing software packages need root privilege, you need to add sudo command before apt-get. Here is an example in real situation:

[email protected]:~$ sudo apt-get update
[sudo] password for luzar:
Hit http://security.ubuntu.com hardy-security Release.gpg
Ign http://security.ubuntu.com hardy-security/main Translation-en_US
Hit http://us.archive.ubuntu.com hardy Release.gpg
Ign http://us.archive.ubuntu.com hardy/main Translation-en_US
...
...
...
Reading package lists... Done
[email protected]:~$

We can update the latest packages list database with apt-get upgrade command.

[email protected]:~$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
linux-image-server linux-server
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

[email protected]:~$

From the apt-get upgrade example above, in the bottom sentence the 2 not upgraded has been intentionally bold. Just to notify you that sometimes you'd see this kind of result. The update is available but your Ubuntu system does not install or upgrade it. To make Ubuntu install or upgrade the updates, you have to use dist-upgrade option instead of upgrade alone. Here is the example:

[email protected]:~$ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
linux-image-2.6.27-9-server
The following packages will be upgraded:
linux-image-server linux-server
2 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 23.5MB of archives.
After this operation, 94.5MB of additional disk space will be used.
Do you want to continue [Y/n]? Y

Normally, this involves an upgrade of the system's kernel as highlighted in blue colored text in the example above. Answer Y to download and upgrade the new updates.

Get:1 http://us.archive.ubuntu.com intrepid-updates/main
linux-image-2.6.27-9-server 2.6.27-9.19 [23.5MB]
0% [1 linux-image-2.6.27-9-server 139910/23.5MB 0%] 3733B/s 1h44min28s

As you can see, apt-get is downloading a Linux image which the size is 23.5MB before it can upgrade the Ubuntu system. This is going to take a while. So, if you have a job to, better switch to different command line terminal.

To install a new software packages with Ubuntu apt-get, we can use the install option. The syntax or command format is apt-get install software_package. Replace software_package with the name of software you want to install. See the example below:

[email protected]:~$ sudo apt-get install nmap
Reading package lists... Done
Building dependency tree
Reading state information... Done
...
...
...
Unpacking nmap (from .../archives/nmap_4.53-3_i386.deb) ...
Setting up nmap (4.53-3) ...

[email protected]:~$

If we need to remove software from Ubuntu system, we can use apt-get remove option. The complete command syntax is apt-get remove software_package. Change the software_package with the name of the package you want to remove. See the example below:

[email protected]:~$ sudo apt-get remove nmap
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libdns32 libisc32
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
nmap
0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded.
After this operation, 3506kB disk space will be freed.
Do you want to continue [Y/n]? Y
(Reading database ... 19065 files and directories currently installed.)
Removing nmap ...
[email protected]:~$

That's all the basics on how to use Ubuntu package management system. Hopefully, all apt-get examples above make sense and help you understand how to install and update packages in Ubuntu command line terminal. Apt-get has been (and still) a very powerful package management system for Ubuntu. You can continue using apt-get if you are comfortable with it or you can check aptitude which is the advanced package management system based on apt-get.

Add new comment