{"id":2688,"date":"2024-02-04T11:35:10","date_gmt":"2024-02-04T11:35:10","guid":{"rendered":"https:\/\/codeinsightacademy.com\/blog\/?p=2688"},"modified":"2024-02-07T03:38:37","modified_gmt":"2024-02-07T03:38:37","slug":"how-to-create-rpm-package","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/linux\/how-to-create-rpm-package\/","title":{"rendered":"How to create rpm package"},"content":{"rendered":"\n<h2>Install required tools<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>rpm -qa | grep rpmdevtools\nyum list | grep rpmdevtools\nyum install rpmdevtools\n<\/code><\/pre>\n\n\n\n<h2>Create directory structure required for rpm build if not exist<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>rpmdev-setuptree\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>rpmbuild\/\n\u251c\u2500\u2500 BUILD\n\u251c\u2500\u2500 RPMS\n\u251c\u2500\u2500 SOURCES\n\u251c\u2500\u2500 SPECS\n\u2514\u2500\u2500 SRPMS\n<\/code><\/pre>\n\n\n\n<h2>Create source package under SOURCES<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir hello-0.0.1\ncd hello-0.0.1<\/code><\/pre>\n\n\n\n<h2>hello.sh<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/sh\necho \"Hello world\"<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>tar -cvzf hello-0.0.1.tar.gz hello-0.0.1<\/code><\/pre>\n\n\n\n<h2>Create spec file and make necessary changes<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\/rpmbuild\/SPECS\nrpmdev-newspec hello.spec<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Name:           hello\nVersion:        0.0.1\nRelease:        1%{?dist}\nSummary:        A simple hello world script\nBuildArch:      noarch\n\nLicense:        GPL\nSource0:        %{name}-%{version}.tar.gz\n\nRequires:       bash\n\n%description\nA demo RPM build\n\n%prep\n%setup -q\n\n%install\nrm -rf $RPM_BUILD_ROOT\nmkdir -p $RPM_BUILD_ROOT\/opt\/hello\ncp * $RPM_BUILD_ROOT\/opt\/hello\n\n%clean\nrm -rf $RPM_BUILD_ROOT\n\n%files\n\/opt\/hello\/*\n\n%postun\nrm -vrf \/opt\/hello\n\n%changelog\n* Sun Feb 04 2024 \n- First version being packaged<\/code><\/pre>\n\n\n\n<h2>Now directory structure should look like this<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/home\/tux\/rpmbuild\/\n\u251c\u2500\u2500 BUILD\n\u251c\u2500\u2500 BUILDROOT\n\u251c\u2500\u2500 RPMS\n\u251c\u2500\u2500 SOURCES\n\u2502   \u2514\u2500\u2500 hello-0.0.1.tar.gz\n\u251c\u2500\u2500 SPECS\n\u2502   \u2514\u2500\u2500 hello.spec\n\u2514\u2500\u2500 SRPMS<\/code><\/pre>\n\n\n\n<h2>Build rpm using following command<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>rpmbuild -ba SPECS\/hello.spec<\/code><\/pre>\n\n\n\n<p>where -b is build a is for both source and binary<br>if you want only binary then put -bb flag<br>if you want only source then put -bs flag<\/p>\n\n\n\n<h2>Install the rpm using following command<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rpm -ivh ~\/rpmbuild\/RPMS\/noarch\/hello-0.0.1-1.el8.noarch.rpm<\/code><\/pre>\n\n\n\n<h2>Verify rpm installed successfully using following command<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>rpm -qi hello\ntree \/opt\/hello<\/code><\/pre>\n\n\n\n<h2>The&nbsp;<strong>%changelog<\/strong>&nbsp;entry of a package can be viewed, too:<\/h2>\n\n\n\n<p>rpm -q hello &#8211;changelog<\/p>\n\n\n\n<h2>Uninstall or erase installed rpm<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo rpm -q | grep hello\nsudo rpm -ve hello<\/code><\/pre>\n\n\n\n<h2>Troubleshoot<\/h2>\n\n\n\n<h2>To extract files and directories from rpm<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>rpm2cpio hello-0.0.1-1.el8.noarch.rpm | cpio -idmv<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Install required tools Create directory structure required for rpm build if not exist Create source package under SOURCES hello.sh Create spec file and make necessary changes Now directory structure should look like this Build rpm using following command where -b is build a is for both source and binaryif you want only binary then put [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2688"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=2688"}],"version-history":[{"count":7,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2688\/revisions"}],"predecessor-version":[{"id":2699,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2688\/revisions\/2699"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=2688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=2688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=2688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}