03 - Linux Package Management
I am an aspiring DevOps Engineer proficient with containers and container orchestration tools like Docker, Kubernetes along with experienced in Infrastructure as code tools and Configuration as code tools, Terraform, Ansible. Well-versed in CICD tool - Jenkins. Have hands-on experience with various AWS and Azure services. I really enjoy learning new things and connecting with people across a range of industries, so don't hesitate to reach out if you'd like to get in touch.
Introduction to Package Managers
One of the common ways to categorize Linux distribution is by the package manager it uses.
For example:
Distributions such as
RHEL,FedoraandCentOS. are based on RPM. Hence they are known asRPMbased distribution.The
Debianfamily includingUbuntu,DebianandLinux Minte.t.c. make use ofDebianbased package managers such as theDPKG.
What is a Package?
A package is a compressed achieve that contains all the files that are required by a particular software to run.
Example:
For Ubuntu System, we want to install a simple editing system such as
gimpwhich stands forGNU Image Manipulation System.To do this, we can make use of the
gimp.debpackage which contains all the software binaries and files needed to for the image editor to run along with the metadata which provides the information about the software itself.
There are hundreds of linux distributions available, and they run different sets of tools and libraries, software and possibly even different linux kernels, as a result of this a linux program may not run the same way from one system to another.
To fix this problem packages include a manifest of dependencies or list of programs in versions that must be satisfied for the package software to run correctly on a given computer.
Each of these dependent packages may have dependencies of their own which makes package installation management a very tedious process. This is where a Package Manager comes in.
Package Manager
- A package manager is a software in a Linux system that provides the consistent and automated process in installing, upgrading, configuring and removing packages from the operating system.
Functions of Package Manager
Package integrity and Authenticity
Simplified Package Management
Grouping Packages
Manage Dependencies
Types of Package Managers
DPKG: Base package manager for Debian-based distributions.
APT: A newer frontend for the
dpkgsystem found in Debian-based distributions such as Ubuntu.APT-GET: Traditional frontend for the
dpkgsystem found in Debian-based distributions.RPM: Base package manager for Red Hat-based distributions.
YUM: A frontend for the RPM system found in Red Hat-based distributions.
DNF: A more feature-rich frontend for the RPM systems.
RPM and YUM
RPM (Redhat Package Manager)
This package manager is used in RHEL as well as other linux distributions.
The File extensions for packages manage by RPM is
.rpm
Working with RPM
RPM has five basic modes of operations.
Each of these modes can be run using
rpmcommand followed by a specific commandoptions.Despite of this, RPM doesn't resolve dependencies on its own. This is why we make use of a higher level of package manager called
YUM.Installing:
[~]$ rpm -ivh telnet.rpm # i = install, v = verboseUninstalling:
[~]$ rpm -e telnet.rpm # e = installUpgrade:
[~]$ rpm -Uvh telnet.rpm # U = upgradeQuery:
[~]$ rpm -q telnet.rpm # q = query into the database (check the package version using this)Verifying:
[~]$ rpm -Vf <path-to-file> # V = verify
YUM (Yellowdog Updater Modifier)
RPM Based Distros: YUM is a free and opensource package managers that works on RPM based Linux systems.
Software Repositories: It works with software repositories which are essentially a collection of packages and provides package independency management on RPM based distro. The repository information is stored in
/etc/yum.repos.d/and repository files will have the.repoextension.High Level Package Manager: It acts as a high level package manager but under the hood it still depeneds on
RPMto manage packages on the linux systems.Automatic Dependency Resolution: Unlike RPM, YUM handles package dependencies very well. It is able to install any dependencies packages to get the base package install on the linux system.
Installing the package using YUM
yum install: YUM first runs transaction check, if the package is not installed in the system, yum checks the configured repositories under/etc/yum.repos.d/for the availability of the requested package.It also checks if there are any dependent packages are already installed in the system or if it needs to be upgrade.
After this step, transaction summary is displayed on the screen for the user to review, if we wish to proceed with the install enter the
ybutton (this step can be skipped by providing the-yflag with theyum installcommand).Yum will download and install necessary RPMs to the system.
If you want to update a single package, use
yum updatecommand. If the package is already in the latest version in the repository and hence no action will be taken.
Commands:
yum repolist: to list all the repos added to the system$ yum repolistyum provide <package-name>: to check which package should be installed for specific command to work.$ yum provides scpyum install <package-name>: to Install a package$ yum install httpdyum install <package-name>: to Install a package. (-y= automatic approval)$ yum install httpd -yyum remove <package-name>: to remove a package$ yum remove httpdyum update <package-name>: to update a package$ yum update telnetyum update <package-name>: to update all packages in the system (without any arguments).$ yum update
DPKG and APT
DPKG (Debian Package Manager)
This package manager is used in Debian-based systems.
The File extensions for packages manage by DPKG is
.deb
Working with DPKG
Similar to RPM, DPKG can be used for the below.
Installation / Upgrade:
dpkg -i telnet.debUninstallation:
dpkg -r telnet.debList:
dpkg -l telnet # list packages installed in the system along with the version number and short descriptionStatus:
dpkg -s telnetVerifying:
dpkg -p <path-to-file> # Displays details about the package eg. version number, maintainer, etc.
APT and APT-GET
Similar to RPM, DPKG doesnt resolve the dependencies when it comes to package management.
Install may fail due to dependencies issues. This is the reason why we use higher level debian package managers such as
APTandAPT-GET.
APT
APTstands for advanced package managers, it is more user friendly and overall better tool compared toAPT-GET.$sudo apt install gimp $sudo apt-get install gimpAPT act as a frontend package manager that relies on DPKG utility.
In similar to YUM, APT relies on software repository that contains packages that would eventually be installed on a system.
The software repository for APT is defined in
/etc/apt/sources.listfile.
Commands
apt update: to refresh a repository.$ sudo apt updateapt upgrade: to install available upgrades of all packages currently installed on the system.$ sudo apt upgradeapt edit-sources: Another way to update the repository. This opens up the/etc/apt/sources.listfile in the text editor of your choice.$ sudo apt edit-sourcesapt install <package-name>: to install the package.$ sudo apt install telnetapt remove <package-name>: to remove the package.$ sudo apt remove telnetapt search <package-name>: to search or look for a package in the repository.$ sudo apt search telnetapt list: to list all the available packages.$ sudo apt list | grep telnet
APT vs APT-GET
APT is a more user friendly tool when compared to APT-GET
In all the latest debian based distros APT is already installed by default.
Why APT is better than APT-GET
Try to install
firefoxpackage using both APT and APT-GET:Search a
telentpackage:With apt, all its options are located in one place and can search with
apt search telnetcommand.On the other hand, there is no search command with
apt-get. Instead, we have to use another tool calledapt-cache search telnet.
apt-cache throws in a lot of extra information in the search result, which may not be really useful for the end user.