Creating a new RPM package
While Oracle provides a large number of RPMs, sometimes you just need to create a custom RPM package that allows you to easily deploy your own software. Creating an RPM file is easy to do!
Getting ready
To do this, you will need a development system, running Oracle Linux 8, with access to the Extra Packages for Enterprise Linux (EPEL) channel. It is highly recommended to have a dedicated system to build RPMs on, and to not build RPMs on production systems. You will also need a system to test installing the RPM on.
Note
Depending on the package being built, you may need additional channels, such as CodeReady or Distro Builder.
There are a few things we need to do first – mainly, installing the RPM developer tools. In order to do this, we also need to add the EPEL repo to the system.
While most of the recipes in this book use the root user for most of the work, this recipe will only use root for the installation of the software. Perform the next few steps as root.
To add the EPEL repo, run the following command:
dnf install oracle-epel-release-el8
Next, run the following commands to enable EPEL and the codeready and distro_builder repos. Having all of these on your build system will make it easier down the road to take advantage of more advanced build tools such as Mock:
dnf config-manager –enable ol8_developer_EPEL
dnf config-manager –enable ol8_codeready_builder
dnf config-manager –enable ol8_distro_builder
Next, we will install the basic utilities to build rpm files. Run the following command to install these:
dnf install -y rpm-build yum-utils rpmdevtools
If you are pulling software from Git, you may need to install git and git-lfs (Git Large File Storage) software. The gcc, make and python3-service-identity RPMs are also common. You can install all of these with the following command:
dnf install -y git git-lfs make gcc python3-service-identity
How to do it…
Now that we have all the tools installed, switch to your non-root user:
- Make a directory for the RPM. Here, we will have a source file for the software, plus all of the files and directories required to make it an RPM. In my case, I am putting everything in /home/erik/.
- Next, we need to make the RPM directory tree. This is done by running the rpmdev-setuptree command. Once you run the command, the tree is created in your $HOME under rpmbuild:
Figure 5.26 – The rpmbuild directories
Five directories are also built, each with a specific purpose:
- BUILD: This is where binaries are saved after being compiled.
- RPMS: RPMs are created here, with rpm files ready for use. There will be subdirectories for different CPU architectures.
- SOURCES: This is where the source code is put, usually a tar file.
- SPECS: This is where the .spec files live.
- SRPMS: Source RPMs are built here – usually, packages containing the source code for the software.
3. Create a simple Bash shell script to distribute as an RPM. This will live in the xyzzy directory in the rpmbuild directory. A simple Bash script is also created:
Figure 5.27 – The xyzzy.sh script
- Next, create a compressed tar file with the contents of the xyzzy directory:
[erik@ol8 rpmbuild]$ tar -cvf SOURCES/xyzzy-1.0.tar.gz xyzzy
xyzzy/
xyzzy/xyzzy.sh
- Now that we have our simple shell script, we need to create the .spec file. The .spec file contains the name of the program, a description of the program, licensing information, project URL, build architecture, and more. The following command will create a default .spec file in the SPECS directory:
rpmdev-newspec SPECS/xyzzy.spec