Table of Contents
Introduction
In this tutorial, How to install an RPM package into a different directory on Centos. Installing RPM packages is a common task for Linux users, especially those working with Red Hat-based distributions like Fedora, CentOS, or RHEL. Sometimes, you may need to install an RPM package into a different directory than the default.
What is an RPM Package?
RPM stands for Red Hat Package Manager. It is a package management system used by Red Hat-based distributions to manage software installation, updates, and removals. RPM packages are precompiled binaries that simplify software distribution and installation.
Why Install RPM Packages into a Different Directory?
There are several reasons why you might want to install an RPM package into a different directory:
- Space Constraints: Your default installation directory might be running out of space.
- Testing: You may want to test a package in a separate environment before moving it to production.
- Custom Configurations: Some applications may require custom directory structures.
For example, Install package bind install into another directory /opt/bind
.
Use rpm -qi command
to check the package has been installed but not yet
$ sudo rpm -qi [name-package]
Not all RPM packages can be installed into another directory.
For example, the bind RPM package is not relocatable. You install it then the error: package bind is not relocatable
[vagrant@DevopsRoles ~]$ rpm -qpi bind-9.8.2-0.68.rc1.el6_10.1.x86_64.rpm | head -1
Name : bind Relocations: (not relocatable)
Install an RPM package into a different directory.
For example, wkhtmltox RPM package
as below
[vagrant@DevopsRoles ~]$ wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox-0.12.5-1.centos6.x86_64.rpm
[vagrant@DevopsRoles ~]$ rpm -qpi wkhtmltox-0.12.5-1.centos6.x86_64.rpm | head -1
Name : wkhtmltox Relocations: /usr/local
[vagrant@DevopsRoles ~]$ sudo rpm -ivh --prefix=/opt/wkhtmltox wkhtmltox-0.12.5-1.centos6.x86_64.rpm
Check the result installed wkhtmltox
on your system.
[vagrant@DevopsRoles ~]$ tree /opt/wkhtmltox
/opt/wkhtmltox
├── bin
│ ├── wkhtmltoimage
│ └── wkhtmltopdf
├── include
│ └── wkhtmltox
│ ├── dllbegin.inc
│ ├── dllend.inc
│ ├── image.h
│ └── pdf.h
├── lib
│ ├── libwkhtmltox.so -> libwkhtmltox.so.0.12.5
│ ├── libwkhtmltox.so.0 -> libwkhtmltox.so.0.12.5
│ ├── libwkhtmltox.so.0.12 -> libwkhtmltox.so.0.12.5
│ └── libwkhtmltox.so.0.12.5
└── share
└── man
└── man1
├── wkhtmltoimage.1.gz
└── wkhtmltopdf.1.gz
7 directories, 12 files
FAQs
Can all RPM packages be relocated?
No, not all RPM packages support relocation. You need to check the package metadata using the rpm -qpi
command to see if it supports relocation.
What if the RPM package does not support relocation?
If the RPM package does not support relocation, you can use the rpm2cpio
and cpio
method to manually extract and place the files in your desired directory.
How do I handle dependencies when relocating RPM packages?
Handling dependencies can be tricky when relocating RPM packages. You may need to manually resolve and relocate dependencies as well. Adjusting environment variables and creating symbolic links can help in managing dependencies.
Is it safe to relocate RPM packages?
Relocating RPM packages can be safe if done correctly. However, it can lead to unexpected behavior if not handled properly, especially with packages that have strict directory dependencies.
Can I use package managers like Yum or DNF to relocate packages?
Yum and DNF do not support package relocation directly. You need to use the RPM command with the --relocate
option or manually extract the package using rpm2cpio
and cpio
.
Conclusion
Installing an RPM package into a different directory can be useful for various reasons, including space management, testing, and custom configurations. While not all RPM packages support relocation, the methods outlined in this guide provide a comprehensive approach to handling different scenarios. Whether using the RPM command with relocation options or extracting packages manually with rpm2cpio
and cpio
, these techniques will help you manage your RPM packages effectively. I hope will this your helpful. Thank you for reading the DevopsRoles page!