制作rpm包

本文详细介绍了如何在Linux系统中制作RPM包,包括安装rpm-build工具,设置rpmbuild目录结构,复制源码,创建并编辑SPEC配置文件,处理构建错误,最后完成RPM软件包的安装和卸载。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

制作rpm包

1)安装rpm-build软件包
[root@web1 ~]# yum -y install rpm-build

2)生成rpmbuild目录结构
[root@web1 ~]# rpmbuild -ba nginx.spec //会报错,没有文件或目录
[root@web1 ~]# ls /root/rpmbuild //自动生成的目录结构

3)准备工作,将源码软件复制到SOURCES目录
[root@web1 ~]# cp nginx-1.12.2.tar.gz /root/rpmbuild/SOURCES/

4)创建并修改SPEC配置文件
[root@web1 ~]# vim /root/rpmbuild/SPECS/nginx.spec

Name:nginx #源码包软件名称
Version:1.12.2 #源码包软件的版本号
Release: 10 #制作的RPM包版本号
Summary: Nginx is a web server software. #RPM软件的概述

License:GPL #软件的协议
URL: www.test.com #网址
Source0:/linux-soft/02/lnmp_soft/nginx-1.12.2.tar.gz #源码包文件的全称

#BuildRequires: #制作RPM时的依赖关系
#Requires: #安装RPM时的依赖关系

%description
nginx [engine x] is an HTTP and reverse proxy server. #软件的详细描述
%post
useradd nginx #非必需操作:安装后脚本(创建账户)

%prep
%setup -q #自动解压源码包,并cd进入目录
%build
./configure
make %{?_smp_mflags}

%install
make install DESTDIR=%{buildroot}
%files
%doc
/usr/local/nginx/* #对哪些文件与目录打包
%changelog

步骤二:使用配置文件创建RPM包
1)安装依赖软件包
[root@web1 ~]# yum -y install gcc pcre-devel openssl-devel
[root@web1 ~]# cp /root/rpmbuild/SOURCES/nginx.spec /root/rpmbuild/SPECS/

2)rpmbuild创建RPM软件包
[root@web1 ~]# rpmbuild -ba /root/rpmbuild/SPECS/nginx.spec

错误:/var/tmp/rpm-tmp.gaiUzR (%build) 退出状态不好

RPM 构建错误:
/var/tmp/rpm-tmp.gaiUzR (%build) 退出状态不好
(解决办法 :vim /root/rpmbuild/SPECS/nginx.spec  ./configure是否写错

[root@web1 ~]# ls /root/rpmbuild/RPMS/x86_64/nginx-1.12.2-10.x86_64.rpm

[root@web1 ~]# cd /root/rpmbuild
[root@room12pc14 rpmbuild]# ls
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
[root@web1 ~]# rpm -qpi RPMS/x86_64/nginx-1.12.2-10.x86_64.rpm
Name : nginx Relocations: (not relocatable)
Version : 1.12.2 Vendor: (none)
Release : 10 Build Date: Mon 02 May 2016 02:30:53 AM PDT
Install Date: (not installed) Build Host: localhost
Group : Applications/Internet Source RPM: nginx-1.8.0-1.src.rpm
Size : 721243 License: GPL
Signature : (none)
URL : www.nginx.org
Summary : Nginx is a web server software.
Description :
nginx [engine x] is an HTTP and reverse proxy server.
[root@web1 ~]# rpm -qpl nginx-1.12.2-10.x86_64.rpm

步骤三:安装、卸载软件
[root@web1 ~]# rpm -ivh RPMS/x86_64/nginx-1.12.2-10.x86_64.rpm

准备中… ################################# [100%]
正在升级/安装…
1:nginx-1.12.2-22 ################################# [100%]
useradd:用户“nginx”已存在
警告:%post(nginx-1.12.2-22.x86_64) 脚本执行失败,退出状态码为 9
(解决办法: 用户已存在,可忽略)

[root@web1 ~]# rpm -qa |grep nginx
[root@web1 ~]# /usr/local/nginx/sbin/nginx
[root@web1 ~]# curl http://127.0.0.1/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值