Linux YUM Configuration and Commands

YUM (Yellowdog Updater Modified) is a package manager for RPM-based distributions like CentOS, RHEL, and Fedora. This page provides details about YUM configuration files, commands, and examples.

Types of URL in YUM

YUM can use different types of URLs to access repositories. The most common types are:

Example of a repository URL in a YUM configuration file:/etc/yum.repo.d/file.repo

        
#HTTP base URL example
[example-repo1]
name=Example Repository
baseurl=http://example.com/repo/
enabled=1
gpgcheck=0

#File base URL example
[example-repo2]
name=Example Repository
baseurl=file:///path/to/local/repo/
enabled=1
gpgcheck=0

#GPG key example
[example-repo3]
name=Example Repository
baseurl=file:///path/to/local/repo/
enabled=1
gpgcheck=1
gpgkey=http://example.com/repo/RPM-GPG-KEY-example
    

In this example, the baseurl is an HTTP URL pointing to the repository.

YUM Configuration File

The main configuration file for YUM is located at /etc/yum.conf. Below is an example of the configuration file:

[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
    

Description of Key Options:

YUM options

YUM supports various options that can be used with its commands. Here are some common options:

YUM Command options

YUM commands can be used with various options to perform different tasks. Here are some common YUM command options:

Option Description Example
install Install a package yum install package_name
remove Remove a package yum remove package_name
update Update all packages or a specific package yum update package_name
search Search for a package by name or description yum search keyword
list List installed or available packages yum list installed
info Display information about a package yum info package_name
clean Clean YUM cache and metadata yum clean all
repolist Display enabled repositories yum repolist
config-manager Manage YUM repositories yum-config-manager --enable repo_name
history View YUM transaction history yum history
downgrade Downgrade a package to an earlier version yum downgrade package_name
groupinstall Install a group of packages yum groupinstall "Development Tools"
groupremove Remove a group of packages yum groupremove "Development Tools"
check-update Check for available updates yum check-update
--nogpgcheck Skip GPG signature checking yum install package_name --nogpgcheck
--downloadonly Download packages without installing them yum install package_name --downloadonly
--refresh Refresh the repository metadata yum update --refresh
--security Check for security updates yum update --security
--noplugins Disable all plugins for the command yum install package_name --noplugins

Common YUM Commands

Below are some commonly used YUM commands with examples:

1. Install a Package

To install a package:

yum install package_name
Example: Install the httpd package:
yum install httpd

2. Remove a Package

To remove a package:

yum remove package_name
Example: Remove the httpd package:
yum remove httpd

3. Update All Packages

To update all installed packages:

yum update

4. Search for a Package

To search for a package:

yum search keyword
Example: Search for packages related to nginx:
yum search nginx

5. List Installed Packages

To list all installed packages:

yum list installed

6. Clean YUM Cache

To clean the YUM cache:

yum clean all

7. Enable/Disable a Repository

To enable or disable a repository:

yum-config-manager --enable repo_name
yum-config-manager --disable repo_name

Create a Repository using createrepo command

To create a YUM repository, you can use the createrepo command. This command generates the necessary metadata for a directory containing RPM packages.

createrepo /path/to/repo

After running this command, the specified directory will contain the necessary metadata files for YUM to recognize it as a repository.

8. View YUM Transaction History

To view the YUM transaction history:

yum history
Example: View the last 5 transactions:
yum history list

9. Downgrade a Package

To downgrade a package to an earlier version:

yum downgrade package_name
Example: Downgrade the httpd package:
yum downgrade httpd

10. Install a Group of Packages

To install a group of packages:

yum groupinstall "Group Name"
Example: Install the "Development Tools" group:
yum groupinstall "Development Tools"

11. Remove a Group of Packages

To remove a group of packages:

yum groupremove "Group Name"
Example: Remove the "Development Tools" group:
yum groupremove "Development Tools"