Package management on Ubuntu
Managing software on your server is a core task. Ubuntu, being based on Debian, uses a powerful system for handling software packages. This article explains the key tools you’ll use: dpkg, apt, and aptitude.
Understanding dpkg
The dpkg command is a fundamental tool for working with Debian package files (.deb files). It’s similar in function to the rpm command used on CentOS servers.
Installing a Package Manually
If you have a .deb file downloaded, you can install it directly using dpkg:
dpkg -i package.debChecking Installed Packages
You can use dpkg to see which programs are currently installed on your server.
To list all installed packages:
dpkg -lTo check if a specific program is installed (useful when combined with grep):
dpkg -l | grep programUsing Apt and Aptitude
Apt (Advanced Package Tool) is the main package manager used by Debian and its derivatives like Ubuntu. It handles downloading packages from repositories and managing dependencies. You interact with Apt primarily through two commands: apt-get and aptitude. They perform many of the same functions, but aptitude has some extra features, particularly for searching.
Installing Packages
To install a package, you can use either command:
apt-get install eximaptitude install eximSearching for Packages
While apt-get can install, you need aptitude to search the repositories for packages:
aptitude search eximViewing Package Information
aptitude can also show details about a specific package:
aptitude show package_nameCommon Apt/Aptitude options
Here are some of the most frequently used options with apt-get and aptitude.
- update: This command downloads the latest information about packages and their versions from the repositories. It’s generally a good practice to run this command every time before installing or upgrading packages.
apt updateor for aptitude
aptitude update- upgrade: Used to update all installed packages on the server to their newest versions. Note: This command can be potentially dangerous and should be run with care.
- apt-get: Use apt-get upgrade.
- aptitude: Use aptitude safe-upgrade (this is equivalent to apt-get upgrade).
- install: Installs one or more specified packages.
apt install package_nameor for aptitude
aptitude install package_name- remove: Removes a specified package from the server, but it leaves configuration files behind.
apt remove package_nameor for aptittude
aptitude remove package_name- purge: Removes a specified package and deletes its configuration files.
apt purge package_nameor for aptitude
aptitude purge package_name- reinstall: (aptitude only) Reinstalls selected packages.
aptitude reinstall package_name- search: (aptitude only) Searches the package repositories.
aptitude search package_name- show: (aptitude only) Displays information about a package.
aptitude show package_nameThis list covers the commands you’ll use most often.
Important caution: Full OS upgrades
While apt-get and aptitude have options for performing full operating system release upgrades (e.g., from Ubuntu 10.04 to 10.10), these commands are extremely risky on conventional Ubuntu releases.
- dist-upgrade (apt-get)
- full-upgrade (aptitude)
These commands attempt to perform a full OS update. However, they very rarely run without issues on Ubuntu releases that aren’t rolling releases. Using these commands is much more likely to cause significant system problems than to work correctly.
The recommended way to upgrade Ubuntu releases is not directly via apt-get or aptitude, but with the separate do-release-upgrade command. Even when using do-release-upgrade, it should still be done with extreme caution, only after performing tested backups.