One of the most common operations found in any OS is software management, including installing, removing, and viewing a list of currently installed packages.
The package management system in Debian (Ubuntu) is built on repositories, which contain links for downloading a huge number of programs.
Essentially, this means you only need to know the name of the program or package. If it exists in a repository on the network, the system will figure out on its own where to download it from for your specific OS version and will install it.
View currently installed packages
# dpkg --list
If you need to find a specific package, for example, to check whether apache2 is installed or not:
# dpkg --list | grep apache2
Searching the repositoryFor this, the "aptitude search" command is used with a parameter that is the package name or part of the name.
# aptitude search apache
In response to this query, aptitude will output a list of all packages matching the name "apache" or containing the phrase "apache" as part of their name.
PS. Throughout the rest of the text I will use the "apache2" package as an example — instead of this name you should substitute the one you want to work with!
Detailed information about a package
# aptitude show apache2
And if you want to view all available versions of a package:
# aptitude show -v apache2
Installing a package from the repository
# aptitude install apache2
In doing so, all dependencies are automatically checked and resolved. So, if the apache2 package depends on the "apache2-mpm-worker" package, that package will be downloaded and installed first, and only then apache2. Here the resolution depth is multi-level — that is, if in turn the apache2-mpm-worker package depends on another package, then that other package will be downloaded and installed first, then apache2-mpm-worker, and only after that — apache2.
This happens almost transparently for the user — aptitude will simply indicate that, in addition to the specified package, it will also download other packages (and will list them).
Installing a specific version of a packageNote! The specified version must exist in the repository, and your OS must know about it (don't forget to update the repository data — see below).
# aptitude install apache2=2.2.9-10+lenny7
As you can see, after the equals sign the full version you want to install is specified.
You can see all versions using the option above — detailed package information.
Reinstalling a package from the repository
# aptitude reinstall apache2
In this case, the package's configuration files will not be overwritten with the default ones.
Removing downloaded installation .deb filesBefore a package is installed, the installation file (.deb file) is downloaded to the computer. After installation, this file is not deleted — for example, in case of reinstallation.
If you need to clean up the cache of downloaded files, use the following command:
# aptitude clean
Removing old and broken installation .deb files
Unlike the previous option, only those installation files that can no longer be downloaded (for example, outdated ones) are removed.
# aptitude autoclean
Removing a package
# aptitude remove apache2
In this case, the package itself will be removed, but the configuration files will be left — in case of reinstallation in the future.
Hard removal of a packageIn this case, all settings will be removed and the OS will try to bring its state back to how it would be if the package had never been installed.
# aptitude purge apache2
Forbidding a package from being updatedIn this case, automatic update procedures will not touch this package, and if a newer version of it is required as a dependency for other packages, then those packages — and everything that depends on their version — will not be touched either.
# aptitude hold apache2
Updating repository dataThis is needed so that the OS always has information about the latest package versions. It must be done before updating packages or, even more so, the OS.
# aptitude update
Updating all packages except the operating system
# aptitude safe-upgrade
This will, of course, resolve all dependencies and update every package that can be updated.
Prevent a package from being upgraded past a certain version
# aptitude forbit-version apache2
# aptitude forbit-version apache2=2.2.9-10+lenny7
This forbids upgrading only to the specified version, while upgrading to a version higher or lower than the one specified is still allowed!
In the first variant, the version immediately following the current one will be forbidden.
In the second variant, you can specify a particular package version that must not be upgraded to.
See an explanation of why a particular package can (or cannot) be installed on the system
# aptitude why apache2
# aptitude why-not apache2
Only download the installation .deb files for the specified packages, without installing them.For example, suppose you've scheduled package installation for a specific time, but you want to prepare in advance by downloading the files to your computer so you don't depend on the internet.
# aptitude download apache2
Simulate an actionIn this case aptitude behaves as it would for the real action, but doesn't actually do anything.
$ aptitude -s action
For example, here's an example of upgrading all packages - aptitude will show everything it would do, without actually doing it:
$ aptitude -s safe-upgrade
Installing a package from a .deb file downloaded separatelyThat is, not from a repository.
# dpkg -i myinstallfile.deb
where instead of "myinstallfile.deb" substitute the name of the downloaded file (and the path, of course).
Removing a package installed from a third-party .deb file
# dpkg -r package_name
where instead of "package_name" specify the package name.
Installing a GPG key
apt-key add - < rep.gpg
where instead of "rep.gpg" specify the name of the downloaded GPG file.
The second way - if the UID is known:
# gpg --keyserver keys.gnupg.net --recv-key 12345678
# gpg -a --export 12345678 | sudo apt-key add -
where instead of "12345678" substitute the known code for this repository.
Comments