How to create a RPM package in Linux
Creating basic installation RPM package is really easy. You just have to use rpmbuild command. rpmbuild will be applied to your source files and a RPM package will be created [all source files will be included in the RPM package]. Somewhere you need to specify the path of your source files. Just before creating the RPM package, your source files will be copied to a temporary location [termed as Build Root]. Actually, you need to write a spec file. rpmbuild will read that file to extract parameters and will act based on the parameter values.
Sample RPM Package
Summary: A summary description of the software. Name: xyz Version: 1.0.0 Release: 1 Group: System Environment/Base BuildRoot: /var/tmp/%{name}-buildroot Prefix:/opt/xyz %description Description of your software %pre%prep%build%installrm -rf /opt/xyz/$RPM_BUILD_ROOTmkdir -p /opt/xyz/$RPM_BUILD_ROOT/dir1mkdir -p /opt/xyz/$RPM_BUILD_ROOT/dir2cp -r your_source_files_path/* /opt/xyz/$RPM_BUILD_ROOT/%post%cleanrm -rf /opt/xyz/$RPM_BUILD_ROOT%files%defattr(-,root,root)/opt/xyz/dir1/opt/xyz/dir2
In the example, BuildRoot is assigned to: /var/tmp/%{name}-buildroot. %install section is doing the building/creation of the RPM package. From Summary to %description are the headers to specify different information as the names indicate. %install section is creating the directories needed and copying your source files to BuildRoot directory(cp -r your_source_files_path/* /opt/xyz/$RPM_BUILD_ROOT/). %files section specifies where rpm package will install your software.%clean section just cleans the BuildRoot directory after the RPM package is created.
Just a note: As I mentioned Prefix to be /opt/xyz, I provided /opt/xyz in the paths. If you keep Prefix to be null, then you need to remove /opt/xyz from the paths. You can place shell commands under %pre section. These command will run just before the RPM package is being installed(using rpm -i command). Under %post section, you can also place some shell commands that will run immediately after the software installation(using rpm -i command). You can use %preor %post section for operations like creating databases, users, and assigning permissions
This may not be 100% perfect. I did not test it on any system, but it should be almost ok. For another example, please visit: http://www.redhat.com/magazine/002dec04/features/betterliving-part2/
The spec file should have name of type name-version_release.spec. After creating the spec file, run the command rpmbuild -ba the_spec_file_name. It will create rpm packages under /usr/src/redhat/BUILD/x86_64 and /usr/src/redhat/SRPMS. You need to copy the spec file under /usr/src/redhat/SPECS/
To install the created RPM package, use rpm -ivh rpmpackagename.rpm command. Look %files section to know where the software will be installed. You can change the path using commands like:rpm -ivh –prefix /opt/rty/ rpmpackagename.rpm. Check our guide on rpm command From: http://sitestree.com/?p=4751
Categories:26, RHCSA
Tags:
Post Data:2009-01-06 06:48:45
Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a>
In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
<a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>