RPM是RedHat Package Manager(RedHat軟件包管理工具)的縮寫,是一種用於互聯網下載包的打包及安裝工具,它包含在某些Linux分發版中。它生成具有.RPM擴展名的文件。使用rpm安裝軟件和管理軟件非常的方便。
1.安裝rpm-build
[root@YunWei-136 ~]# yum -y install rpm-build redhat-rpm-config
2.建立目錄結構
[root@YunWei-136 ~]# mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} [root@YunWei-136 ~]# tree -n ~/rpmbuild/ /root/rpmbuild/ ├── BUILD 存放源代碼 ├── RPMS 存放用於管理rpm製作進程的spec文件 ├── SOURCES 解壓後的文件存放在這裏 ├── SPECS 存放由rpmbuild製作好的二進制包 └── SRPMS 存放由rpmbuild製作好的源碼包 5 directories, 0 files
3.下載源碼包
[root@YunWei-136 ~]# wget -P ~/rpmbuild/SOURCES/ http://nginx.org/download/nginx-1.4.7.tar.gz
4.製作.spec文件
[root@YunWei-136 ~]# cd ~/rpmbuild/SPECS [root@YunWei-136 SPECS]# vim nginx.spec Name: nginx Version: 1.4.7 Release: 1%{?dist} Summary: nginx rmp package production Group: Applications/Archiving License: GPLv2 URL: http://www.nginx.org Source: http://nginx.org/download/nginx-1.4.7.tar.gz BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) BuildRequires: gcc Requires: openssl,openssl-devel,pcre-devel,pcre %description Custom nginx rpm package %prep rm -rf $RPM_BUILD_DIR/nginx-1.4.7 tar fx $RPM_SOURCE_DIR/nginx-1.4.7.tar.gz %build cd nginx-1.4.7 ./configure \ --prefix=/home/application/nginx \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-http_gzip_static_module make %{?_smp_mflags} %install rm -rf %{buildroot} cd nginx-1.4.7 make install DESTDIR=%{buildroot} %clean rm -rf %{buildroot} %files %defattr(-,root,root,-) /home/application/nginx
5.spec文件解釋
#:以#開頭是註釋,rpm會忽略它。 Summary: 簡單描述軟件。 Name : 定義rpm的名稱。 Version: 定義軟件版本 Release: 發行版本 License: 定義許可證 Group: 軟件分類 Source: 源碼下載地址 URL: 源碼相關網站 Distribution: 發行版系列 Packager: 打包人的信息 %description:軟件詳細描述,可多行 %prep :軟件編譯之前的處理,如解壓。 %build :開始編譯軟件,如make %install :開始安裝軟件,如make install %files :指定哪些文件需要被打包,如/usr/local/nginx %preun :定義卸載之前的動作,如殺掉進程。 這裏只介紹了幾個常用的tag,更詳細的請參考:http://www.rpm.org/max-rpm/ch-rpm-inside.html
6.開始RPM製作
[root@YunWei-136 SPECS]# rpmbuild -bb nginx.spec
6.測試RPM包
[root@YunWei-136 SPECS]# yum -y install /root/rpmbuild/RPMS/x86_64/nginx-1.4.7-1.el6.x86_64.rpm Loaded plugins: fastestmirror Setting up Install Process Examining /root/rpmbuild/RPMS/x86_64/nginx-1.4.7-1.el6.x86_64.rpm: nginx-1.4.7-1.el6.x86_64 Marking /root/rpmbuild/RPMS/x86_64/nginx-1.4.7-1.el6.x86_64.rpm to be installed Loading mirror speeds from cached hostfile * base: mirrors.btte.net * epel: ftp.riken.jp * extras: mirrors.btte.net * updates: mirrors.btte.net Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 0:1.4.7-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================================================== Package Arch Version Repository Size ================================================================================================================================================================================================================== Installing: nginx x86_64 1.4.7-1.el6 /nginx-1.4.7-1.el6.x86_64 732 k Transaction Summary ================================================================================================================================================================================================================== Install 1 Package(s) Total size: 732 k Installed size: 732 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : nginx-1.4.7-1.el6.x86_64 1/1 Verifying : nginx-1.4.7-1.el6.x86_64 1/1 Installed: nginx.x86_64 0:1.4.7-1.el6 Complete!
至此,nginx的RPM包製作完成,併成功安裝......大家可以舉一反三製作其他軟件的RPM包。