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:
- HTTP/HTTPS: Standard web protocols for accessing repositories over the internet.
- FTP: File Transfer Protocol, used for accessing repositories hosted on FTP servers.
- Local: Accessing local directories or files as repositories.
- File: Accessing local files directly, typically used for offline installations.
- EPEL: Download a Extra packages through the internet
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:
cachedir: Directory where YUM caches packages.keepcache: Whether to keep the cache after installation (0 or 1).debuglevel: Debugging level (0-10).logfile: Path to the log file.gpgcheck: Enable/disable GPG signature checking (0 or 1).plugins: Enable/disable YUM plugins (0 or 1).
YUM options
YUM supports various options that can be used with its commands. Here are some common options:
-y: Automatically answer "yes" to prompts.--enablerepo=repo_name: Enable a specific repository.--disablerepo=repo_name: Disable a specific repository.--nogpgcheck: Skip GPG signature checking.--setopt=option=value: Set a specific option for the command.--downloadonly: Download packages without installing them.--refresh: Refresh the repository metadata.--security: Check for security updates.--best: Use the best available version of a package.--noplugins: Disable all plugins for the command.
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
httpd package:
yum install httpd
2. Remove a Package
To remove a package:
yum remove package_name
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
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
yum history list
9. Downgrade a Package
To downgrade a package to an earlier version:
yum downgrade package_name
httpd package:
yum downgrade httpd
10. Install a Group of Packages
To install a group of packages:
yum groupinstall "Group Name"
yum groupinstall "Development Tools"
11. Remove a Group of Packages
To remove a group of packages:
yum groupremove "Group Name"
yum groupremove "Development Tools"