How Do You Install an rpm/yum/dnf Package in a Non-Stardard Location?

Problem scenario
A partition is filling up on CentOS/Stream/RHEL/Fedora Linux. You do not want to have a package be installed in /usr or some "normal" location. You want to uninstall a package and reinstall it elsewhere. But moving the directory won't work because the binary command will point to the old location. What should you do to get the destination of the installation to be something customized (and not the default directory)?

Use a yum or dnf command to install it with these two flags: --installroot=/destination/ --releasever=9

Replace "desination" with the directory you want it to be installed in (e.g., /opt/ or your own path). Replace "9" with the major RedHat version you are using. If you are unsure, run this: sudo cat /etc/*-release

This would install foobar in /opt if you were using RHEL version 9:
sudo dnf -y install foobar --installroot=/opt --releasever=9

This will create a full set of FHS directories. If you choose a location that has already been used as an --installroot, the …/repos.d/ file will be consulted for the location of the installation media. (Some people do not care for this functionality; see this posting if you are interested.) You could move the relevant yum.repos.d directory to a yum.repos.d.bak directory. Then the normal yum/dnf/rpm repos will be used on the system. In newly created directories or any directory where the location has not already been the target of such the --installroot flag, there will be no problem. This does create many more files and takes up space.

You can see this for more information:

Leave a comment

Your email address will not be published. Required fields are marked *