Repository and Package Management on Linux

Repository and Package Management on Linux

Subscribe to our newsletter and never miss any upcoming articles

Listen to this article

Software installation is an vital part while working on any operating system. Installing applications on Windows Operating system is very straight forward as you just need to double click on the executable file and follow the subsequent prompts and that's all!

On Unix and Linux it's totally a different ball game. How it is different than Windows, how to configure repositories etc. In this article I will be demonstrating the end to end process of repository and software management process on Linux.

What are Software Repositories?

All the Linux distributions hosts their own software repositories. A Linux user no need to go to vendor's websites in order to download the applications unlike on Windows.

It's a centralized storage location from where the Linux systems retrieves, installs software updates and applications. These repositories contains specially compiled packages in accordance with the OS distribution and version.

What are Package Managers?

Package Manager is a tool which enables a Linux user to download, install, uninstall or upgrade software packages in an automated manner.

They play a very crucial role in Linux software management. They keep tracks of all the software's installed on you system and notify you whenever a new update or upgrade is available for an application or for the Operating system itself.

Every Linux distribution for example Ubuntu, Red Hat or Arch Linux everyone has their own Package Manager tools. We will discuss about this in coming sections.

What is a Package?

A package contain all of the necessary files, meta-data, and instructions to implement a particular functionality or software application on your system.

Package Management on Ubuntu Linux

Ubuntu’s has a very comprehensive and extremely matured package management system which is originally acquired from the Debian Linux distribution.

Configuring Software repositories on an Ubuntu System

I am using Ubuntu 18.04 LTS system for this demo purpose.

ubuntu_details.png

The place to configure software repositories on all Debian based operating systems like Ubuntu is either in /etc/apt/sources.list file or can be configured in separate files under the /etc/apt/sources.list.d/ directory. The name of the files must end with .list extension.

apt_location.png

sources_list_file.png

Lines starting with hash (#) are comments which are used for documentation purposes. Comments can also be used to disable a certain package repository.

There are four main repositories on Ubuntu systems:

repo_description-ubuntu.png

This is how these repositories are configured in sources.list file.

cat sources.list | grep -v "^#" | grep -i main

cat sources.list | grep -v "^#" | grep -i universe

cat sources.list | grep -v "^#" | grep -i restricted

cat sources.list | grep -v "^#" | grep -i multiverse

repo_configs_sources_list.png

Each line starting with deb or deb-src adds a package repository on your Linux system.

deb -> These repositories contain binaries or precompiled packages. These repositories are required for most users.

deb-src -> These repositories contain the source code of the packages. Useful for developers.

To understand a repository entry in sources.list file let us take an example entry here.

deb http://archive.ubuntu.com/ubuntu/ bionic main restricted

repo_entry_description.png

Web locations of these repositories ->

Attaching few snapshots from the web url's of these repositories.

archive.ubuntu.com/ubuntu/ubuntu

ubuntu_repo_weburl.png

archive.ubuntu.com/ubuntu/ubuntu/ubuntu/ubu..

ubuntu_repo_weburl-2.png

archive.ubuntu.com/ubuntu/ubuntu/ubuntu/ubu..

ubuntu_repo_weburl-3.png

Adding custom repositories on Ubuntu

We need to configure custom repositories for the applications which are natively not available with Ubuntu's official repositories which we have discussed above.

Here we will add Jenkins repository to our Linux system. Before adding the repository if you try to install the Jenkins package you will get the following error:

before_adding_repo.png

Run the following commands to add it to our system.

Step 1 -> Import the public key used by the package management system

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -

Step 2 -> Create a list file and add repository config for Jenkins

sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

add_custom_repo-ubuntu.png

Step 3 -> Update the repositories Run the following command which reload the database for local package on all the repositories.

apt-get update

Untitled design.png

Now try to install the Jenkins package.

after_adding_repo.png

You can add Repositories with add-apt-repository command as well. The repository will be appended to sources.list file. The syntax would be like this - add-apt-repository [options] repository

For example:

add-apt-repository 'deb http://pkg.jenkins.io/debian-stable binary/'

apt-add-repo.png

In order to remove a custom repository the command syntax would be like this: add-apt-repository --remove repository

For example:

add-apt-repository --remove 'deb http://pkg.jenkins.io/debian-stable binary/'

apt-add-repo-remove.png

Package Manager Tools on Ubuntu

There are four type of package manager tools exists on Ubuntu.

Below table briefly introduces them.

ubuntu_pkg_mgrs.png

Package Manipulation commands on Ubuntu

Below table introduces commands to perform various package related operations on Ubuntu Linux.

ubuntu_pjg_manager_tools.png

Package Management on CentOS Linux

On Red Hat Linux / CentOS distributions we can do package management through CLI and from the GUI as well. Here I will demonstrate the CLI way of doing this.

Configuring Software repositories on a CentOS System

I am using CentOS Linux 7 system for this demo purpose.

centos_release.png

The place to configure software repositories on CentOS is /etc/yum.repos.d directory. The name of the files must end with .repo extension.

centos-repo-dir.png

Here is a sample repo file:

centos-repo_sample_file.png

Lines starting with hash (#) are comments which are used for documentation purposes. Comments can also be used to disable a certain package repository.

Adding custom repositories on CentOS Linux

We need to configure custom repositories for the applications which are natively not available with CentOS's official repositories.

Here we will add EPEL (Extra Packages for Enterprise Linux) repository to our Linux system. It is an additional package repository which enables us to install packages for commonly used software.

Install EPEL Repo via yum ->

Run the following commands to install epel repository on your CentOS Linux system. Here we are using yum which a Package Manager tool on Red Hat based systems. We will learn more about it in next section.

Search and get information about the epel-release package.

yum search epel-release

yum info epel-release

search_epel.png

Now Install the epel-release package.

yum install -y epel-release

install_epel.png

Now you will find epel repo files under /etc/yum.repos.d directory.

epel_yum_repos_dir_files.png

Verify the EPEL Repo Installation: Run the following command to verify the repo installation.

yum repolist

yum_repolist.png

Package Manager Tools on CentOS

There are three type of package manager tools exists on CentOS.

centos-pkg-mgr-tools.png

dnf is default package manager since Fedora 22 in 2015 and Red Hat Enterprise Linux 8.

Package Manipulation commands on CentOS

Below tables introduces commands to perform various package related operations on CentOS Linux using different package management tools.

yum_commands.png

rpm_commands.png

dnf_commands.png

Syntax to import gpg keys on CentOS Linux systems is ->

rpm --import <key_file_path>

Using yum-config-manager in RHEL/CentOS Linux

yum-config-manager is a tool to manage yum configuration options and yum repositories.

Add repository with yum-config-manager ->

yum-config-manager --add-repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo

jenkins_repo_centos.png

Enabling a yum Repository using yum-config-manager ->

Run the following command to enable a yum repository.

yum-config-manager --enable jenkins

yum_config_enable_repo.png

You can see the enabled parameters value is set to 1.

Disabling a yum Repository using yum-config-manager ->

Run the following command to disable a yum repository.

yum-config-manager --disable jenkins

yum_config_disable_repo.png

You can see the enabled parameters value has been changed to 0 from 1.

That's all for this detailed guide covering all aspects of Package and Repository Management on Linux systems.

Hope you like the article. Stay Tuned for more.

Thank you. Happy learning!

 
Share this