Package Managers
On Linux, software is typically built as a package, distributed through repositories, and managed on the end-user’s system through package managers. Each Linux system typically contains thousands of packages, many of which are required dependencies for other packages.
DPKG and APT
Debian-based distributions uses dpkg package management system while apt and apt-get provides high-level interface for dpkg. Apt uses network repositories to get precompiled packages and can resolve dependencies between packages, so it is advised to use this method to install software to your system. Dpkg can be used when installing package from different sources. A Debian "package", or a Debian archive file, contains the executable files, libraries, and documentation associated with a particular suite of program or set of related programs. Normally, a Debian archive file has a filename that ends in .deb.
LPI Learning Material 101 - Chapter 102.4 (Pages 100 - 121)
Overview of apt commands
Apt is operating in local database of available packages in the repositories. If the package change in the repository, local database don't know about this change until it is updated. So as the best practice before you start installing new packages, you should update your local database first.
Update local database
sudo apt update
Or within shell script use:
sudo apt-get update
Perform upgrade
If there are packages to upgrade you can show the list by executing apt list --upgradable
.
To perform upgrade of available updates run command:
sudo apt upgrade
Or if you run the command from script and want to install upgrade silently, run following command:
sudo apt-get upgrade -y
Install package
To install packages use:
sudo apt install <package_name>
sudo apt install <package_name1> <package_name2> <package_name3>
sudo apt install <package_name>=<version_number>
Or within shell script with automatic dependency resolve use:
sudo apt-get install -y <package_name>
Removing unused package
When there are package we do not use any longer, we might want to remove them from the system. Following command will remove package and any unnecessary depedencies but it will maintain the configuration files of the package.
sudo apt remove <package_name>
If you want to completely remove the package including all configuration files, you can use following command.
sudo apt purge <package_name>
Searching package and showing its details
If you need to find a specific package, or if you don't know the full package name and need to find it you can use following command.
apt search <package_name>
apt search <keyword>
Or using older CLI use:
apt-cache search <package_name>
apt-cache search <keyword>
When you find desired package, you can view its details using following command.
apt show <package_name>
Or using older CLI use:
apt-cache show <package_name>
List packages
By running following command you can view list of packages that have newer version in the repository.
apt list --upgradable
To view all installed package on your system just run following command.
apt list --installed
RPM and YUM/DNF
Similarly in RPM-based distributions you can find basic package management system called rpm using package with .rpm file extension. And for performing high-level package administration you can use older yum or newer dnf.
LPI Learning Material 101 - Chapter 102.5 (Pages 122 - 147)