Some RPM packages can be installed in another directory, otherwise known to be relocatable. Some RPM packages you will not be able to do this for. You can easily check if an RPM package can be installed in another directory with the following command:
# rpm -qpi package.rpm | head -1
Name : package Relocations: (not relocatable)
You can see that the above output will let you know if its not relocatable. Alternatively, it might show a path under relocations.
# rpm -qpi package.rpm | head -1
Name : package Relocations: /usr
If it is relocatable then you can install the RPM package to a different directory than the default by using the --prefix
argument:
rpm -ivh --prefix=/different/directory package.rpm
Finally you can verify that it was indeed installed in your custom directory with the following command:
rpm -ql package
That will output the files that were placed and show you exactly what directories they exist in. You are looking to see if they were indeed put in your custom directory.
If you try to do this on a RPM package that is NOT Relocatable, than you would get an error like this:
rpm -ivh --prefix=/different/directory package.rpm
error: package package is not relocatable