rpm打包

时间:2021-06-18 18:11:31

1,需要安装rpmbuild

2,准备好工作目录:

mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

3,自定义环境:

vim ~/.rpmmacros
%_topdir /root/rpmbuild
%_tmppath /root/rpmbuild/tmp
%buildroot /root/rpmbuild/BUILDROOT
%_prefix /

4,将tarball拷贝到~/rpmbuild/SOURCES下

5,创建相应spec文件(举例nginx):

Summary: nginx-1.6.
Name: nginx
Version: 1.6.
Release:
Source0: %{name}-%{version}.tar.gz
License: GPL
Group: Development/Tools
BuildRoot: %{_builddir}/%{name}-root
%description
nginx-1.6. %prep
%setup -q %build
./configure
make -j4 %install
make DESTDIR=$RPM_BUILD_ROOT install
%clean
rm -rf $RPM_BUILD_ROOT %files
%defattr(-,root,root)
/usr/local/nginx/conf/fastcgi.conf
/usr/local/nginx/conf/fastcgi.conf.default
/usr/local/nginx/conf/fastcgi_params
/usr/local/nginx/conf/fastcgi_params.default
/usr/local/nginx/conf/koi-utf
/usr/local/nginx/conf/koi-win
/usr/local/nginx/conf/mime.types
/usr/local/nginx/conf/mime.types.default
%config /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.default
/usr/local/nginx/conf/scgi_params
/usr/local/nginx/conf/scgi_params.default
/usr/local/nginx/conf/uwsgi_params
/usr/local/nginx/conf/uwsgi_params.default
/usr/local/nginx/conf/win-utf/usr/local/nginx/html/50x.html
/usr/local/nginx/html/index.html
/usr/local/nginx/sbin/nginx

1),其中%file段只写 /usr/local也没有问题,因为它实际是从 $RPM_BUILD_ROOT/usr/local/下拷贝的文件

2),%install 段:

make DESTDIR=$RPM_BUILD_ROOT install

这是由相应tarball 的configure文件决定的,若不是标准的,则有可能不是指定DESTDIR这个变量。如php5:

make INSTALL_ROOT=$RPM_BUILD_ROOT  install

否则打包会找不到文件

6,

rpmbilld -ba xxxx.spec

7,去RPMS目录下检查RPM包

rpm -Vp XXXXXXX.rpm # or -qpl