The apt command is one of the most powerful and versatile tools in the Linux operating system. It provides users with a powerful, yet easy-to-use, package management system that can be used to easily manage and install the software. With the apt command, users can quickly and easily search for, install, upgrade, and uninstall software applications from their systems.
This guide provides a detailed overview of the apt command and explains how to use it to manage software on a Linux system. It explains the different commands and options available and outlines how to use them to manage software, resolve software dependencies, and keep your system running smoothly and efficiently.
The apt package manager is used in several Linux distributions, including:
- Debian and its derivatives (such as Ubuntu and Linux Mint)
- Kali Linux
Updating Apt Index (apt update)
Before you can use the Apt package manager, you will need to update the package repositories. The package repositories are online databases that contain information about available packages. To update the package repositories, use the update command:
sudo apt update
This will download the latest package information from the repositories.
Installing Packages (apt install)
By default, the Apt package manager will install the latest available version of a package. To install a package named `foo` type:
sudo apt install foo
However, sometimes you may need to install a specific version of a package. To do this, use the = operator followed by the version number when installing the package. For example, to install version 1.2 of the package foo, run the following command:
sudo apt install foo=1.2
Searching for a Package (apt search)
You can use the
`apt search` command followed by the search string. For example, to search for packages related to the word “foo”, run the following command:
sudo apt search foo
This will display a list of packages that match the keyword.
Keep Your System Up to Date (apt ugprade)
One of the most important best practices for managing packages with the Apt package manager is to keep your system up to date. New versions of packages are released regularly to fix bugs and security vulnerabilities. To update your system, use the upgrade command:
sudo apt upgrade
This will upgrade all installed packages to their latest available version.
To upgrade a specific package, you should use the apt install command with the
sudo apt --only-upgrade install foo
This will install the latest version of the package only if it is already installed.
Downgrading a Package to a Previous Version
To downgrade a package to a previous version, use the install command with the = operator and the version number of the previous version. For example, to downgrade the package foo to version 1.2, run the following command:
sudo apt install foo=1.2
Note that this will overwrite the current version of the package, so be sure to make any necessary backups before downgrading.
Remove Packages (apt remove)
You can use the `apt remove` command to remove specific packages. For example, to remove the package foo, run the following command:
sudo apt remove foo
This will remove the package, but it will leave behind any dependencies that are still needed by other packages.
Removing Unused Dependencies (apt autoremove)
When you install a package, it may bring in other packages as dependencies. These dependencies are required for the package to function correctly. However, once you remove the package, these dependencies may no longer be needed. To remove these unused dependencies, use the autoremove command:
sudo apt autoremove
This will remove any dependencies that are no longer needed by any installed packages.
Use Apt Pinning to Control Package Upgrades
Apt pinning allows you to control which packages are upgraded and when they are upgraded. This can be useful if you want to prevent a specific package from being upgraded to a newer version. To use Apt pinning, you will need to edit the /etc/apt/preferences file and add a pinning rule.
For example, to prevent the package foo from being upgraded, add the following line to the `/etc/apt/preferences` file:
This will prevent the package foo from being upgraded, but it will still be updated if a security vulnerability is discovered.
Use Apt Snapshots to Roll Back Package Upgrades
Apt snapshots allow you to roll back package upgrades to a previous version if something goes wrong. To create a snapshot, use the apt-mark command to mark all installed packages as “manual”:
sudo apt-mark manual `apt-mark showmanual`
Then, use the apt-get command to create a snapshot:
sudo apt-get install apt-rdepends
sudo apt-rdepends -d --state-show=installed
Replace “package_name” with your package name. This will create a snapshot file called apt-snapshot.txt that contains a list of all installed packages and their dependencies. To roll back to a previous snapshot, use the apt-get install command and specify the snapshot file:
sudo apt-get install --reinstall -y \ -o APT::Get::ReInstall=true \ -o APT::Get::Show-Upgraded=true \ -o Debug::pkgProblemResolver=true \ -f -V < apt-snapshot.txt
Show Pacakge Information (apt show)
This command allows you to view all the information about a specific package, including its version, its dependencies, and more. With apt show, you can quickly find out what a certain package does, and whether it's right for your system. You can also check to make sure that you have the latest version of a package, or even downgrade it if necessary. So if you're a Linux user looking for detailed package information.
sudo apt show foo
So if you're a Linux user looking for detailed package information, you can use `apt show` to find it quickly and easily.
Cleaning the Package Cache (apt clean)
The Apt package manager keeps a cache of all the packages that you have installed or downloaded. Over time, this cache can become large and take up a lot of disk space. To clean the package cache and free up disk space, use the clean command:
sudo apt clean
This will remove all the packages from the cache that are no longer needed.
In this article, we covered some advanced techniques for using the Apt package manager. We showed you how to install a specific version of a package, upgrade all packages to their latest version, downgrade a package to a previous version, remove unused dependencies, and clean the package cache. These techniques can help you more effectively manage packages on your Linux system.
apt-rdepends -d –state-show=installed > apt-snapshot.txt
seems to be wrong ==>
apt-rdepends [options] [pkgs …]
-b, –build-depends show build dependencies
-d, –dotty generates a dotty graph
-p, –print-state show the state of each dependency
-r, –reverse list packages that depend on the specified one
-f, –follow=DEPENDS only follow DEPENDS dependencies recursively
-s, –show=DEPENDS only show DEPENDS dependencies
–state-follow=STATES only follow STATES states recursively
–state-show=STATES only show STATES states
–help display this help and exit
–man display the man page and exit
–version output version information and exit