Linux Commands

How to Install Package to a Specific Directory Using Yum

Installing packages in any Linux-based Operating system is like a task that happens on a daily basis, and it is seen that we often need to install some packages for a brief period. However, the packages required for very little time stay inside our system and consume the disk space.

In a system where we have fewer resources in terms of disk space, the disk space stays almost full, and we have to keep check on unwanted applications and packages and remove them from time to time.

For such scenarios where you have to install and use some packages for a short period, it is a better practice and recommended to install the packages in some specific or temporary directory. The directory will stay separate from all other package clusters, and you can easily remove the packages.

Yum vs. DNF

Yum, an abbreviation of “Yellow Updater modified,” is a primary package manager for installing packages in CentOS or any RHEL-based operating system. While DNF, shortened for “Dandified Yum,” is the latest and feature-enriched package manager compared to Yum.

In the latest versions of the RHEL-based operating system, it is recommended to use DNF instead of Yum. This post will provide a detailed guide on installing a package to a specific directory using Yum and DNF package manager.

The syntax for installing a package:

Usually, we install a package using the syntax provided below:

$ sudo dnf <options> install <package-name>

The option we can use for installing a package to a specific directory is:


In the option mentioned above, we can provide a specific directory path where we want to install the package.

Let’s try to install a package to demonstrate how to install a package to a specific directory.


For example, we want to install git in some specific directory like /opt/temp-packages.

Let’s first create a “temp-packages” directory inside the /opt directory in which we want to install Git.

$ sudo mkdir temp-packages

To install git in the /opt/temp-packages directory, we will provide the path to the –installroot option in the yum install command as shown below:

$ sudo dnf --installroot=/opt/temp-packages --releasever=/ install git

In the above command, we also need to use the –releasever option while creating installroot. Otherwise, we will have to face an error as shown in the screenshot attached below:

So, execute the installation command with the –releasever=/ option.

Type ‘y’ for granting additional disk space usage and begin the installation process of the package you want to install.

In the above screenshot attached, you can witness the installation of Git in the /opt/temp-packages directory.

Once you are done with the installation of the package, head to the /opt/temp-packages directory and execute the ls command to view the files and directories in the /opt/temp-packages directory:

$ cd /opt/temp-packages
$ ls

You can see that a completely separate environment is created inside the /opt/temp-packages directory.

To use any package installed in a specific directory, we can move to the /usr/bin directory and run it because we all know that the packages are installed in the /usr/bin directory. So, navigate to the usr/bin directory, which is inside the /opt/temp-packages, using the command given below:

$ cd /opt/temp-packages/usr/bin

In the bin directory, execute the ls and grep command to verify if the desired package is installed or not. The command for finding and verifying the package installation will go like this:

$ ls | grep "git"

To verify and know the installed version of Git, you can type the command provided below in the bin directory:

$ ./git --version

Or you can also verify the installation of Git by executing the simple ./git command in the /opt/temp-packages/usr/bin directory:

$ ./git

You can witness that git is installed successfully in the /opt/temp-packages directory and working perfectly fine as we want it to work.


This post contains a brief and detailed explanation on how to install a package to a specific directory using the Yum or DNF package manager by using the –installroot option. This post also demonstrates the whole process of installing a package to a specific directory and using that package. As an example, we installed Git in the “/opt” directory using the –installroot option and learned how to start using it.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.