1. Create a program
[builduser@jmnote ~]$ mkdir hello-1.0.0 [builduser@jmnote ~]$ cat <<EOF > hello-1.0.0/hello > #!/bin/bash > echo world > EOF [builduser@jmnote ~]$ sh hello-1.0.0/hello world
2. gzip
[builduser@jmnote ~]$ tar czvf hello-1.0.0.tar.gz hello-1.0.0/ hello-1.0.0/ hello-1.0.0/hello
3. Make a spec file (hello.spec)
[builduser@jmnote ~]$ vi hello.spec
Name: hello Version: 1.0.0 Release: 1%{?dist} Summary: A hello package Group: Testing License: GPL URL: http://jmnote.com/testing Source0: %{name}-%{version}.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: /bin/rm, /bin/mkdir, /bin/cp Requires: /bin/bash %description A hello package %prep %setup -q %build #configure #make %{?_smp_mflags} %install rm -rf $RPM_BUILD_ROOT #make install DESTDIR=$RPM_BUILD_ROOT mkdir -p $RPM_BUILD_ROOT/usr/local/bin cp hello $RPM_BUILD_ROOT/usr/local/bin %clean rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root,-) #%doc %attr(0755,root,root)/usr/local/bin/hello %changelog * Sat May 17 2014 Jmnote <jmnote@example.com> - 1.0.0 - Initial RPM
4. rpm build
[builduser@jmnote ~]$ rpmbuild hello.spec error: File /home/builduser/rpmbuild/SOURCES/hello-1.0.0.tar.gz: No such file or directory
[builduser@jmnote ~]$ cp hello-1.0.0.tar.gz rpmbuild/SOURCES/ [builduser@jmnote ~]$ cp hello.spec rpmbuild/SPECS/ [builduser@jmnote ~]$ cd rpmbuild/SPECS/ [builduser@jmnote SPECS]$ rpmbuild --sign -ba hello.spec Enter pass phrase:
Pass phrase is good. Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.hUcv0F + umask 022 + cd /home/builduser/rpmbuild/BUILD + cd /home/builduser/rpmbuild/BUILD ... (생략) + cd hello-1.0.0 + rm -rf /home/builduser/rpmbuild/BUILDROOT/hello-1.0.0-1.el6.x86_64 + exit 0
[builduser@jmnote SPECS]$ cd ../RPMS/x86_64/ [builduser@jmnote x86_64]$ ll total 4 -rw-rw-r--. 1 builduser builduser 2546 May 17 02:24 hello-1.0.0-1.el6.x86_64.rpm
5. rpm installation and confirmation
[root@zetawiki ~]# rpm --import /home/builduser/RPM-GPG-KEY-builduser [root@zetawiki ~]# cp /home/builduser/rpmbuild/RPMS/x86_64/hello-1.0.0-1.el6.x86_64.rpm ~ [root@zetawiki ~]# rpm -ivh hello-1.0.0-1.el6.x86_64.rpm Preparing... ########################################### [100%] 1:hello ########################################### [100%]
[root@zetawiki ~]# rpm -qa hello hello-1.0.0-1.el6.x86_64 [root@zetawiki ~]# which hello /usr/local/bin/hello [root@zetawiki ~]# rpm -qf /usr/local/bin/hello hello-1.0.0-1.el6.x86_64 [root@zetawiki ~]# hello