Centos环境下 helloworld rpm的制作,安装,卸载

前端之家收集整理的这篇文章主要介绍了Centos环境下 helloworld rpm的制作,安装,卸载前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

安装rpm-build,rpmdevtools等工具

我的制作目录在 /root/rpmbuild/下,用户直接root


刚开始的目录文件如下,其他目录都是空的

SOURCES
│   └── helloworld-0.1-1.tar.gz
SPECS
│   └── helloworld.spec
tar中的文件内容如下
├── helloworld
│   ├── configure
│   ├── helloworld.c
│   └── readme
  • helloword.c
#include <stdio.h>

int main()
{
    printf("Hello World!\n");
    return 0;
}
  • configue (chmod u+x ),就是makefile相关
#!/bin/sh
cat >Makefile  << EOF
all:helloworld
helloworld.o:helloworld.c
    gcc -c helloworld.c
helloworld:helloworld.o
    gcc helloworld.o -o helloworld
fresh:
    rm -f Makefile
clean:
    rm -f helloworld helloworld.o
install:
    cp helloworld /usr/bin
uninstall:
    rm -f /usr/bin/helloworld
EOF

helloworld.spec

Summary:the first rpm
Name:helloworld
Version:0.1
Release:1%{?dist}
Vendor:john
License:Share
Group:Applications/Text
Source0:helloworld-0.1-1.tar.gz
#Patch0:hellow-0.1-1.patch
%description
rpm test helloworld
 %prep
export RPM_SOURCES_DIR=/root/rpmbuild/SOURCES 
export RPM_BUILD_DIR=/root/rpmbuild/BUILD
tar -xzvf $RPM_SOURCES_DIR/helloworld-0.1-1.tar.gz
#%patch -p0`
 %build
cd $RPM_BUILD_DIR/helloworld
./configure
make
 %install
cd $RPM_BUILD_DIR/helloworld
make install
 %clean
rm -rf $RPM_BUILD_DIR/helloworld
 %files
%defattr(-,root,root)
/usr/bin/helloworld
 %doc $RPM_BUILD_DIR/helloworld/readme

第一次rpbuild会出现如下的错误

# rpmbuild -ba SPECS/helloworld.spec 

需要修改spec文件
添加两句话到%install下面

%install
cd $RPM_BUILD_DIR/helloworld
make install
mkdir -p /root/rpmbuild/BUILDROOT/helloworld-0.1-1.el6.x86_64/usr/bin/
cp $RPM_BUILD_DIR/helloworld/helloworld /root/rpmbuild/BUILDROOT/helloworld-0.1-1.el6.x86_64/usr/bin/

重新rpmbuild后成功生成相应的rpm文件

  • 验证rpm(rpm的安装,卸载)

参考:
http://www.cnblogs.com/bluevitality/p/6513097.html

http://dl.download.csdn.net/down6/20090203/1a8c80d1eb06761a1052f94dbe46c0eb.rar?response-content-disposition=attachment%3Bfilename%3D%22makerpmhellow.rar%22&OSSAccessKeyId=9q6nvzoJGowBj4q1&Expires=1498286502&Signature=TeqnlB1sldzGUbs%2Fi%2FHy75BG8FM%3D

原文链接:https://www.f2er.com/centos/377064.html

猜你在找的CentOS相关文章