Applications (installing and using)

Package Management for Debian and Ubuntu

Apt is the main command line package tool for Debian and Ubuntu. It features dependency management, so if you install a package, it will also install any additional packages required to make that work. It has version management, so you can just install the package by name and it will choose a version that works with your system.

Apt also handles security updates, you should use that on a regular basis to remove known vulnerabilities from your system.

If your server has a control panel installed such as cpanel or Plesk, it is best not to run apt manually on the command line, but to use the control panel for that. Using apt on the command line could break your server in some cases. Webmin usually plays well with apt, so you can work either through Webmin or using command line apt. Use whichever you are most comfortable with.

Working with Apt


# update the db of available packages.  Do this before running the other commands.
apt-get update
 
# upgrade currently installed packages to the most stable version
apt-get upgrade
 
# find what package provides some functionality you're after
apt-cache search somekeyword
 
# install a new package
apt-get install nameofthepackage

# remove a currently installed package
apt-get remove nameofthepackage

Apt Sources

Apt knows about which packages are available by consulting lists of packages which get downloaded from the net when you run apt-get update. You can view and manage apt's sources by editing the file /etc/apt/sources.list, and the files in /etc/apt/sources.list.d/ (files there must end with a .list extension to be effective). Sometimes when adding software to your system the instructions will tell you to modify the apt sources, or sometimes installing a third party program (such as the Google Chrome browser) will add an apt source file automatically.

On Ubuntu, the add-apt-repository command can be used to add a new apt source.

You should always run apt-get update whenever your apt sources change, and whenever you start to use apt. This keeps apt's list of packages current, but doesn't make any changes to what's actually installed on your server.

Security and Stability updates

The apt-get upgrade command will upgrade packages unless new dependencies are required for those. If you don't change your sources list, you can run this without risking upgrading to incompatible versions (e.g. that need different configuration files.)

You should update your system regularly, e.g. weekly, to ensure you are not vulnerable to known OS exploits. You can either do that manually, or configure your system for automatic upgrades. For further information on how to do that, see Keeping your server up to date.

Distribution upgrades

One of the goals of apt, which is still a point of difference for Debian and some derived distributions, is the ability to upgrade a distribution in place, that is upgrade software so your server runs a later version of Debian. You could do that by modifying the sources.list file to point to the later release, and then running apt-get dist-upgrade. Ubuntu have depreciated that in favour of their own command for upgrading (do-release-upgrade). However, there is a better way to do a distribution upgrade than those methods.

We recommend using the distrorejuve tool, which uses apt in the background but also does a number of other tasks to ease the upgrade. For more information about both distrorejuve and manual upgrades see Upgrading Debian and Upgrading Ubuntu.

Resolving: The following packages have been kept back

You may get this message when you run apt-get upgrade. It means one of the updated packages has a dependency which does not currently exist on your system. Try an apt-get update first, if that doesn't work it could be an indication that your sources list has changed, and that is causing problems. Perhaps see the section on distribution upgrades above.

Low-level package management - DPKG

The dpkg command is the lower-level tool used by apt to actually install, upgrade and remove individual packages. You won't normally need to use that unless apt is broken for some reason.

Working with dpkg


# Install a deb
dpkg -i packagename.deb

# to find out summary information about a .deb package
dpkg --info packagename.deb

# to find out what files are in a .deb package
dpkg --contents packagename.deb

#To list all packages installed on your server
dpkg -l

# To find out if a particular package is installed
dpkg -l thepackagenameyoureinterestedin

#To find out which deb installed a particular file on your server, run:
dpkg -S /path/to/filename

APT for Red Hat/CentOS

Apt was originally only available for Debian users, and equivalent functionality was not available for Red Hat derived distros. Then apt was ported to Red Hat/rpm, and RimuHosting started providing apt with those distros. More recently Red Hat started supporting yum, which is now the standard equivalent tool used by RH/CentOS. Consequently, if you have an older CentOS system, you may find both apt and yum installed. You should normally use yum on CentOS systems these days in preference to apt.