This tutorial explains how to configure Yum with local repository in RHEL/Centos Linux including some important Yum commands which are used for Linux package management.
Basic overview of Yum
Yum is the default package management utility in RHEL/Centos Linux. Yum is used to search, install, update and remove necessary rpm files from system. RHEL/Centos Linux use .rpm file to manage the software. A .rpm file extension represents Linux software package file. Yum uses repository to manage the rpm files. A repository is the collection of RPM files. Since Yum depends on repository, there must be at least one working repository before it can be used. A repository can be configured either locally (on local hard) or remotely (on network or internet).
- YUM stands for Yellow Dog Updater Manager.
- Yum is the default package management utility in RHEL/Centos.
- Yum uses repository to get the necessary rpm files.
- A repository is collection of rpm files.
- Repository may contain multiple versions of the same RPM package.
- Repository may contain different builds for different architectures for example one for i686 and other for x86_64.
- A repository can be configured locally or remotely.
- Yum can automatically resolve software dependencies and based on system hardware it can automatically select appropriate version of RPM package from repository.
Yum Repository Configuration Files
Whenever we use Yum command, it checks yum repository configuration files to get the list of available repositories. Yum repository configuration files are stored in /etc/yum.repos.d/ directory and have .repo extension. By default these files are configured to use only official online repositories. In RHCSA or RHCE exam we are not allowed to use Internet. Luckily both exam and Yum command allows us to use local repository. In this tutorial we will learn how to create and use a local repository.
On Job Tips
Repositories are operating system specific. They will not work with other flavor of Linux for example a RHEL repositories will not work with Centos system and vice versa a Centos repositories will not work with RHEL system. In Red Hat Linux repositories are provided through the RHN network. To use RHN network we need to have an active subscription. During the installation, RHEL asks us to register the system with RHN network. If system is registered with RHN network and subscription is active, default configuration is sufficient to install software packages. If system is not registered with RHN network, it will never be able to connect with Red Hat official repositories. For this reason it is recommended to use Centos instead of Red hat, if free version of RHEL Linux is needed.
How to create a local yum repository
Before we create repository, we need to get all necessary RPM package files. For this, we can use RHEL/Centos installation disk. As we know repository is operating system specific, we have to use the same disk which we used to install the operating system. If RHEL is installed, we have to use the RHEL installation disk. If Centos is installed then we have to use the Centos installation disk.
Let’s insert installation disk in system and mount it.
By default all media disks are mounted in /run/media/UserName/ directory. Here UserName is the name of logged in user.
Create a directory. Since this directory will be used to store all RPM package files from disk, make sure we have sufficient (at least 4GB) free disk space. In this tutorial we will use /rhcelab/repo directory.
Copy all RPM package files from installation disk to /rchelab/repo directory. Replace /rchelab/repo with your own path, if you are using other directory.
Switch to /rhcelab/repo directory and install creatrepo package.
Now run createrepo /rhcelab/repo command.
During this process several cache files are generated. Let’s remove them.
That’s all we need, our local repository is ready to use. But wait at this point yum command can’t use this repository.
Can you figure out why?
Yep, you got it right. Yum command uses repository configuration files to figure out the available repositories. And so far we haven’t created the necessary repository configuration file for our local repository.
Create an rhcelab.repo file in /etc/repos.d/ directory with following contents
Let’s understand the meaning of above contents step by step
|vi /etc/yum.repos.d/rhcelab.repo||As we know repository configuration files are stored in /etc/yum.repos.d/ directory with an extension .repo, So we executed this command to create the necessary configuration file for repository.|
|[rhcerepo]||This is the label of repository. Usually a repository file contains configuration for multiple repositories. In that case label is used as identifier of repository.|
|name=rhcerepo||This configuration value is used to set the name of repository.|
|baseurl=file:///rhcelab/repo||This configuration value defines the location of rpm files.|
|enabled=1||This key defines the state of repository. If value is set to 1 then repository is enabled. If value is set to 0 then repository is disabled.|
|gpgcheck=0||This key defines whether the integrity of package should be check or not. If value is set to 1, integrity will be checked. If value is set to 0, integrity will not be checked.|
|:wq||We used vi editor to create the file. In vi editor, the command: wq is used to save and quit from file.|
How to define the baseurl key
- To define local directory path use file:///directory_path.
- To define FTP path use ftp://hostname/path_to_directory_which_has_rpms
- To define HTTP path use http://hostname/path_to_directory_which_has_rpms
- To define NFS path use file://hostname/path_to_directory_which_has_rpms
- You may use IP address at the place of hostname, if DNS is not configured.
The gpgcheck key
By default yum is configured to use online repositories. If repository server is compromised, a hacker may put some fake packages in repository or may change existing packages. If these packages are installed in system, the system may get hacked also. The GPG key is the counter measurement of this kind of security threat. The packages in repository are signed with GPG key. The owners of packages also provide the GPG keys. With GPG key yum can check whether the package is in its original state or has been modified in repository. Since in our local repository we put all packages from original installation disk, there is no need to enable the GPG check feature.
We can verify the newly created repository with yum repolist command.
As output confirms that our repository (name – rhcerepo and id - rhcerepo) is ready to use. Currently this repository contains 4751 packages.
Now we have a working repository, in remaining part of this tutorial we will learn how to use the repository.
Linux package management with yum command
The yum command is used to work with repository. Before we explore yum command in details let’s have a quick look on some important options used with this command.
|Option / Sub command||Description|
|provides / whatprovides||Perform a deep scan in all rpm for specified file.|
|search / search all||Search for specified package|
|list installed||List all installed packages in system|
|list||List all packages available from all enabled repositories.|
|list all||List all packages available for installation from all enabled repositories as well as those that are already installed.|
|group list||List all groups that are available for installation|
|info||Provide detailed information about package|
|install||Install the specified package|
|remove||Remove the specified package|
|update||Update the specified package|
To install, remove or update a package we first need to know the exact name of the package. Since packages name contain a lot of information in name (such as version, architecture, platform etc.), they are hard to remember. We can use two sub commands to get the exact name of a package; search and provides.To find out all packages which have specified string in name we can use following command
#yum search SearchString
For example to search any package which contains semanage in the name we can use following command
#yum search semanage
By default this command will search for specified string only in name and summary. To search everywhere in package we have to use all option with this command.
Following figure illustrates the use of both commands.
If we know the command but don’t the package name which provides the specific command, we can use provides or whatprovides sub command. For example to know which package provides chocon command we can use following command
#yum provides */chocon
This command will perform a deep scan in all RPM for file name chocon. Linux commands have an associated script file which executes when command is called at shell prompt.
We can also use whatprovides sub command instead of provides command.
#yum whatprovides */chocon
There is no functional difference between provides and whatprovides sub command.
Following figure illustrates the use of booth commands.
Once we got the exact package name, we can use info sub command to get the more detailed information about the package. For instance, in above example we figured out that chcon command is provided by coreutils package. To get more information about this package we can use following command
When we install a package with yum command, it creates necessary directory tree at appropriate location and installs required files from package. It also checks for dependencies. If any file in package depends on other files, yum will also install those files automatically. During installation if yum finds any file which is already installed in system from package, it will check its current version. If package contains latest file, it will update the existing file. By default yum command will ask for confirmation. To perform installation without confirmation we have to use –y option.
For example following command will install the vsftpd package with confirmation
Following command will install package without confirmation
To remove a package we can use remove sub command. Just like install, remove operation is also performed with dependency which means yum will not only remove the specified package but all remove all the packages that depend on it. For this reason, even it supports –y option, we should not perform remove operation without confirmation. Remove operation should always be performed with confirmation.
Following command will remove vsftpd package with confirmation.
That’s all for this tutorial. In next tutorial we will learn another Linux topic in detail.