Oct 09, 2017. Today I am able to create.rpm file from spec file in ubuntu. Using alien filename.rpm I got.deb file. I ran.deb file with dpkg -i and it was successful. But in my system rpmdev-setuptree command is not working and I do not know how I got rpmbuild tree structur where I ran above things. So I want to understand full procedure of RPM in ubuntu.
I have already written article to build a signed rpm from scratch by building a source archive using Red Hat Linux, now in this article I will share the steps to rebuild rpm using source rpm. The source rpm can be collected from official page of respective distribution. In this article I will use httpd source rpm to rebuild the httpd rpm
Install rpmdevtools
We need
NOTE:rpmdev-setuptree
to setup rpmbuild
directory structure to create rpm package. The tool is provided by rpmdevtools in RHEL/CentOS 7 LinuxIf you do not have an active repository then download rpms with all the list of dependencies using which then you can create an offline repository.
There are some other pre-requisite rpms which are required to create rpm package. Some of them are:
Now later when we build rpm from source code, it is possible we may get any more dependency error, so we will install any additional rpms based on the requirement.
Create rpmbuild structure
To create rpm package using
rpmbuild
, we need a proper directory structure. rpmbuild
will look for files from respective directories to build rpm from source codeRun the
rpmdev-setuptree
utility from the location where you wish to setup the rpmbuild structure to create rpm package. I will execute under root's home folderAs you can see a directory structure is created by
rpmdev-setuptree
under /root/rpmbuild
We will cover two scenarios to create rpm package
- Build rpm from source code
- Create rpm package from scratch
Build RPM from source code
In this example, we already have an rpm, but we would like to modify the rpm content and build rpm from the source code with our modifications.
Step 1: Download source rpm
First we must access the source rpm which we have to modify to create rpm package. You can get the source rpm depending upon your environment and vendor. Videoboxpro 1 2 1 – professional video captures capture.
I will take a basic example of
httpd
rpm, and the src rpm was available at CentOS project repositoryStep 2: Extract source rpm content
Next we will extract the source code from the rpm. I have created a temporary directory
/tmp/customrpm
to extract the content of httpd
rpm.Copy the
httpd
source rpm to this temporary directoryExtract the source code using
rpm2cpio
Movist 2 0 0 beta 25 download free. Next extract the
httpd-2.4.6.tar.bz2
archive so that we can modify the content of httpd
. This contains all the source code for httpd package.Step 3: Modify the Source Code
If you observe we have multiple patch and other configuration files available inside our temporary directory.
Now based on your source rpm, the content of the rpm may vary. I will go ahead and put some dummy data in one of the files under
httpd
and later we will use the new changes to build rpm from source code.Step 4: Create RPM Content Archive
Next I will create a new archive under
/tmp
with the updated source code.In the later steps we will transfer this archive to
SOURCE
directory of the rpmbuild structure to build rpm from source codeSo now since I have created a new archive, I will remove the extra content from my temporary directory.
It will help me arrange the files required to create rpm package later.
Step 5: Update SOURCES
Next we will copy the new archive to
SOURCES
directoryStep 6: Update rpm spec File
A
spec
file is always part of any rpm. So when we extracted our src rpm, we also got httpd.spec
file, we will copy the httpd.spec file to SPEC
directory. We will need this to create rpm package with a new version.It is always a good idea to modify the version of rpm and provide the list of changes performed in the source code to track the changes
Step 7: Build rpm using source code
If you check the
spec
file, you will find BuildRequires
section. This contains pre-requisite which are required by httpd rpm for installationSo before we start to build rpm from source code, we have to make sure the build machine has these rpms installed and those files available on your host.
To get the complete list of dependencies you can initiate
rpmbuild
and it will throw you the dependencies list. Here -ba
means Build binary and source packages (after doing the %prep, %build, and %install stages).The rpmbuild will throw an error will the dependency error. So we must manually install these dependency rpms before we can create rpm package:
![How To Install Rpmbuild On Ubuntu How To Install Rpmbuild On Ubuntu](https://2.bp.blogspot.com/_okRBto_1nro/TAnlbgP4rBI/AAAAAAAAABA/c0z5lNpg5ck/S226/gangtux_ubuntu.png)
Once all the dependency rpms are installed, you can again trigger
rpmbuild
to build rpm from source code.So our create rpm package was successful. At the end of execution you can see the path of the new rpm files under
RPMS
directory of the rpmbuild structure.Step 8: Install and Validate RPM
I will install the new rpm to verify the changes which I had done to the
README
file of our httpd rpm.Verify if the rpm is successfully installed
Get the path of
README
file where we did the changes of our source rpm:So looks like our changes are present as expected:
Create rpm package from scratch
- It is possible you want to create a completely new rpm package for your development and testing tasks.
- We will need similar
rpmbuild
directory structure - It is important that you create separate rpmbuild structure for individual rpm
- I will create a new rpm by my name '
deepak
' - So I will create a new folder to create
rpmbuild
structure
Execute
rpmdev-setuptree
to create rpmbuild
structure to create rpm packageThis will create similar directory structure as we created earlier to build rpm from source code
Step 1: Create rpm spec file
Since we plan to create rpm package from scratch, we would need a spec file. You can refer fedora: create rpm packages to get a sample
spec
fileOr you can use below
spec
file template for your rpm
- One of the most important part of spec file are
scriptlets
- Using
scriptlets
we can define%pre
,%post
and many other sections of rpmspec
file - So you can use respective section to call a custom script or function
- For example, you have a requirement to setup an environment before installing the rpm, so you can choose respective
scriptlets
to add your changes. - I have written separate article to cover all the scriptlets with detailed examples
Step 2: Create RPM content
- All the content under
SOURCES
will be considered as rpm content - These will be placed on the server after rpm is installed
- The location of these content will be defined using rpm
spec
file - We do not keep individual files in
SOURCES
, instead we must bundle the content and then place the bundle inSOURCES
directory
So I will create a temporary directory under
/tmp
.Below will be our source directory with base release number of 1.0.0
Next lets create some dummy files and directories which we have mentioned in the spec file under
%files
Step 3: Update SOURCES
Next we will create an archive using the temporary file and directory we created above. The archive must use proper release and version number
For example my
For example my
spec
file contains below![Install Install](https://4.bp.blogspot.com/-BhvFOywPTJY/TVUH8wJJ99I/AAAAAAAAAJA/39llHNxA93U/s320/ubuntu-microsoft-fonts.png)
So my archive name would be
deepak-1.0.0-1.tar.gz
Step 4: Create RPM package
Apt Get Qt
So our
rpmbuild
environment setup is complete. Next we will create rpm package using rpmbuild
with the spec fileOur rpmbuild execution is successful.
The new rpm is placed under
/root/deepak/rpmbuild/RPMS/x86_64/deepak-1.0.0-1.x86_64.rpm
Step 5: Install and Verify rpm content
Let us check the content of our rpm
Install and validate the rpm
The rpm installation was successful and the content of the rpm remains the same
Ubuntu Rpm Command Not Found
What's next?:Ubuntu Software Center
Now you have created an rpm package but this rpm is not secure as it is not signed. So you must sign your rpm package using GPG key
Ubuntu Software Center Download
Lastly I hope the steps from the article to create rpm package and build rpm from source code using rpmbuild on Red Hat Linux was helpful. So, let me know your suggestions and feedback using the comment section.