RPM/YUM - Tips and Tricks

I am writing this blog post to share my experience with RPM package and repository management. Based on my experience I have included information which are useful for basic administration of RPM packages in Linux system.

Why do we need RPM package ?

Initially all the softwares used in Linux were available as a tar file, the tar file would contain all the files related to software. A user would extract the tar file, compile the software and then install it. This approach has two major disadvantages.

  • Once software is installed its hard to keep track of all the files installed in different paths in file system and its not easy to remove/update software.
  • If application has some dependency then you need to manually install it before installing your application.
What is RPM package?

This problem is solved by packaging all the software and its metadata in a package called RPM. The RPM package contains version, list of files, dependencies, description of a package etc. If software is installed using RPM file, its easy to keep track of software version, dependencies and file paths.

RPM commands

RPM command is more useful for querying a installed package. To query the package, user the -q option.

1. To list all the installed RPMs in the system.

# rpm -qa

2. To check if specific RPM is installed in the system.

# rpm -qa <package name>
# rpm -qa httpd

3. To find out which package belongs to a specific file.

# rpm -qa <file path>
# rpm -qf /etc/yum.conf

4. To list all the files in a package.

# rpm -ql <package name>
# rpm -ql yum

5. To check the dependencies of RPM package.

# rpm -qR <package name>
# rpm -qR yum

6. To list change log for the package.

# rpm -q --changelog <package name>
# rpm -q --changelog yum | less
YUM commands

The Yellowdog Updater, Modified (yum) is a command line tool to manage RPM packages and repositories. While RPM tool does not install package dependencies by default, yum take cares of package dependencies. To install/remove/update RPM packages from the system and to check yum transaction history, you will need to run command as a root user.

1. To install RPM package.

# yum install <package name>
# yum install httpd

This command will install httpd package with all its dependencies. If any dependency is missing in repository, it will fail with dependency error.

During installation it gives you option to download the package Is this ok [y/d/N]:. Here d refers to "Download Only", if specified rpm will be downloaded in /var/cache/rpm. You can also pass multiple RPMs with install option

yum install <pkg1> <pkg2>....<pkgn>  

2. To remove any RPM package.

# yum erase <package name>
# yum erase httpd

3. To update a RPM package.

# yum update <package name>
# yum update httpd

4. To update all the RPMs in a system.

# yum update

5. To get the information about a package.

# yum info <package name>
# yum info httpd

6. To find out which package provides a specific library/command.

# yum provides <binary/command name>
# yum provides sar

7. To check history of all yum transactions in a system, we can run below command which will display transaction-id, date and time, action etc.

# yum history

We can use "history" option to rollback any yum transaction.

# yum history undo <transaction id>
# yum history undo 2 -y

8. To display the configured repositories in the system.

# yum repolist

9. It is often useful to remove cached data accumulated in the /var/cache/yum/ directory.

# yum clean all
How to create a yum repository ?

We will be creating a test repository and host it over httpd. We are going to use two centOS 7 system here. One system will serve as a yum repository server and another will act as a client.

Server IP -  
Server Configuration
  • Install the httpd package
# yum install httpd -y
  • Create a directory called custom_repo under /var/www/html for repository and copy rpms in the directory.
# mkdir -p /var/www/html/custom_repo

If you are creating a test repository you can download RPMs using yumdownloader, it is a tool to download RPMs from yum repositories.

# yumdownloader <pkg1> <pkg2> ....<pkgn>
  • The createrepo rpm is required to create a yum repository.
# yum install createrepo -y 
  • The createrepo command will generate repodata in custom_repo directory. After verifying that repodata is generated, start the httpd service.
# createrepo /var/www/html/custom_repo
# ls -l /var/www/html/custom_repo/repodata
# systemctl start httpd

You can verify repository by browsing

Client Configuration

There are two ways to add repository in your client system.

  • Create a repository file custom.repo in /etc/yum.repos.d/ and add content manually.
Name - Name of the repository  
baseurl - Repository location  
enabled - To enabled repository set value as 1. To disable, 0.  
gpgcheck - To enable gpgcheck set value as 1. To disable, 0.  
  • Run yum-config-manager command to add repository, it will automatically create repo file in /etc/yum.repos.d directory.
# yum-config-manager --add-repo

Now try to install rpm in your client system.

# yum install <package name>
File paths for configuration and troubleshooting
  • /etc/yum.conf - Yum main configuration file
  • /etc/yum.repos.d/ - Repositories configuration file
  • /etc/yum/ - Other yum configuration files
  • /var/cache/yum/ - Yum cache location
  • /var/log/yum.log - Yum log file
  • /var/lib/rpm/ - All the information about the installed RPMs are stored in the RPM database. The files in that directory are Berkeley DB files.

I have included commands which I find useful for my day-to-day task. To find out all the commands/features provided by yum and rpm tool either you can use --help option or man page.