阅读更多
前言
所有操作在root权限下执行
一.将之前我们制作tarball软件包复制到/root/rpmbuild/SOURCES上面并打包
复制
cp -r /usr/local/src/sort-average /root/rpmbuild/SOURCES
进入/root/rpmbuild/SOURCES目录
cd /root/rpmbuild/SOURCES
改目录名
mv sort-average sort-average-0.1
打包
tar -zcvf sort-average-0.1-1.tar.gz sort-average-0.1
二.在/root/rpmbuild/SPECS目录编写sort-average.spec文件
Summary: sort 10 integers or average 5 integers
Name: sort-average
Version: 0.1
Release: 1
License: GPL
Group: jison`s home
Source: sort-average-0.1-1.tar.gz
Packager: jison
BuildRoot: /root/rpmbuild
%description
This package will let you sort 10 integers or average 5 integers
%prep
%setup -q
%build
make
%install
mkdir -p %{buildroot}/usr/local/bin
cp /root/rpmbuild/BUILD/sort-average-0.1/sort-average %{buildroot}/usr/local/bin
make install RPM_INSTALL_ROOT=%{buildroot}
%files
/usr/local/bin/sort-average
三.根据sort-average.spec文件生成RPM包
rpmbuild -ba sort-average.spec
-ba 编译并同时生成RPM与SRPM文件
-bb 仅编译成RPM文件
然后就可以在/root/rpmbuild/RPMS/x86_64文件夹看到打包好的RPM包了
cd /root/rpmbuild/RPMS/x86_64
ls
结果为
sort-average-0.1-1.x86_64.rpm
sort-average-debuginfo-0.1-1.x86_64.rpm
四.删除打包过程安装的sort-average命令并重新用打包好的sort-average-0.1-1.x86_64.rpm包安装sort-average命令
卸载tarball方法安装的sort-average命令
rm -f /usr/local/bin/sort-average
安装 sort-average-0.1-1.x86_64.rpm包
cd /root/rpmbuild/RPMS/x86_64
rpm -ivh sort-average-0.1-1.x86_64.rpm
五.测试安装好的sort-average命令
sort-average
Please input 's' or 'a or 'q':a
Please input 5 integers to average:
1 2 3 4 5
average:
3
Please input 's' or 'a or 'q':s
Please input 10 integers to sort:
5 6 4 3 2 1 54 6 3 4
after sort:
1 2 3 3 4 4 5 6 6 54
Please input 's' or 'a or 'q':q
exit...
六.卸载sort-average命令
rpm -e sort-average-0.1-1.x86_64.rpm