centos浅谈之rpm和rpmbuild
分类:CentOS教程 阅读:25173 次
一、简介
RPM(Red Hat Package Manager)是用于 Linux 分发版(distribution)的最常见的软件包管理器。RPM包命名方式:name-version-release.architecture.rpm。RPM有五种基本的操作功能:安装、卸载、升级、查询和验证。这五种基本功能的实现仅仅需要用rpm + 选项 + rpm包就能轻易地实现。
如果想发布rpm格式的源码包或者是二进制包,就要使用rpmbuild工具(rpm最新打包工具)。rpmbuild根据本地源码包的成功编译安装而写了spec文件(该文件要以.spec结束)。
二、详解
1、RPM
(1)rpm二进制包(.rpm文件)
常用命令组合:
- -ivh:安装显示安装进度--install--verbose--hash
- -Uvh:升级软件包--Update;
- -qpl:列出RPM软件包内的文件信息[QueryPackagelist];
- -qpi:列出RPM软件包的描述信息[QueryPackageinstallpackage(s)];
- -qf:查找指定文件属于哪个RPM软件包[QueryFile];
- -Va:校验所有的RPM软件包,查找丢失的文件[ViewLost];
- -e:删除包
1)安装:
rpm -i your-package.rpm(your-package.rpm是rpm包的文件名),安装过程中可能出现下面的警告或者提示:.. conflict with ... ,则可能是要安装的包里有一些文件可能会覆盖现有的文件,缺省时这样的情况下是无法正确安装的可以用rpm-i--force强制安装即可。若出现... is needed by ...和... is not installed ... 此包需要的一些软件你没有安装可以用rpm-i--nodeps可以忽略所有依赖关系和文件问题,什么包都能安装上,但这种强制安装的软件包不能保证完全发挥功能 。
2)查询:
rpm -qa 将列出所有安装过的包 ,rpm-qa|grephttpd #[搜索指定rpm包是否安装]--all搜索*httpd*
rpm-qlhttpd #[搜索rpm包]--list所有文件安装目录
which mysql #查找rpm包中的文件安装到那里去了
rpm-qpiLinux-1.4-6.i368.rpm #[查看rpm包]--query--package--installpackage信息
rpm-qpfLinux-1.4-6.i368.rpm #[查看rpm包]--file
rpm-qpRfile.rpm #[查看包]依赖关系
查找rpm中包含哪些文件:一个没有安装过的软件包,使用rpm -qlp *.rpm;一个已经安装的软件包,可以使用rpm -ql *.rpm 。
获取关于一个软件包的信息:一个没有安装过的软件包,使用rpm -qlp *.rpm ;一个已经安装过的软件包,使用rpm -qi *.rpm。
- %definelivearches%{ix86}x86_64ppcppc64
- %define_libdir%{_prefix}/lib
- Summary:Graphicalsysteminstaller
- Name:anaconda
- Version:13.21.176
- Release:1%{?dist}
- License:GPLv2+
- Group:Applications/System
- URL:http://fedoraproject.org/wiki/Anaconda
- #TogenerateSource0do:
- #gitclonehttp://git.fedorahosted.org/git/anaconda.git
- #gitcheckout-barchive-branchanaconda-%{version}-%{release}
- #./autogen.sh
- #./configure
- #makedist
- Source0:%{name}-%{version}.tar.bz2
- Patch1000:anaconda-centos-installclass.patch
- Patch1001:anaconda-centos-upgrade-from-centos.patch
- Patch1002:anaconda-centos-droprepos.patch
- BuildRoot:%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u}-n)
- #Versionsofrequiredcomponents(donesowemakesurethebuildrequires
- #matchtherequiresversionsofthings).
- %definedmver1.02.17-6
- %definegettextver0.11
- %definegenisoimagever1.1.9-4
- %defineintltoolver0.31.2-3
- %definelibnlver1.0
- %definelibselinuxver1.6
- %definepykickstartver1.74.8
- %definerpmpythonver4.2-0.61
- %defineslangver2.0.6-2
- %defineyumver2.9.2
- %definepartedver1.8.1
- %definepypartedver3.0
- %definesyscfgdatever1.9.48
- %definepythonpyblockver0.45-2
- %definee2fsver1.41.0
- %definenmver1:0.7.1-3.git20090414
- %definedbusver1.2.3
- %definecreaterepover0.4.7
- %defineyumutilsver1.1.11-3
- %defineiscsiver6.2.0.870-3
- %definepythoncryptsetupver0.0.6
- %definemehver0.8
- %definesckeyboardver1.3.1
- %definelibblkid2.17.1-1
- %definefcoeutilsver1.0.12-3.20100323git
- %defineisomd5sumver1.0.6
- BuildRequires:audit-libs-devel
- BuildRequires:bzip2-devel
- BuildRequires:device-mapper-devel>=%{dmver}
- BuildRequires:e2fsprogs-devel>=%{e2fsver}
- BuildRequires:elfutils-devel
- BuildRequires:gettext>=%{gettextver}
- BuildRequires:gtk2-devel
- BuildRequires:intltool>=%{intltoolver}
- BuildRequires:isomd5sum-devel>=%{isomd5sumver}
- BuildRequires:libarchive-devel
- BuildRequires:libX11-devel
- BuildRequires:libXt-devel
- BuildRequires:libXxf86misc-devel
- BuildRequires:libblkid-devel>=%{libblkid}
- BuildRequires:libcurl-devel
- BuildRequires:libnl-devel>=%{libnlver}
- BuildRequires:libselinux-devel>=%{libselinuxver}
- BuildRequires:libsepol-devel
- BuildRequires:libxml2-python
- BuildRequires:newt-devel
- BuildRequires:pango-devel
- BuildRequires:pykickstart>=%{pykickstartver}
- BuildRequires:python-devel
- BuildRequires:python-urlgrabber>=3.9.1-5
- BuildRequires:rpm-devel
- BuildRequires:rpm-python>=%{rpmpythonver}
- BuildRequires:slang-devel>=%{slangver}
- BuildRequires:xmlto
- BuildRequires:yum>=%{yumver}
- BuildRequires:zlib-devel
- BuildRequires:NetworkManager-devel>=%{nmver}
- BuildRequires:NetworkManager-glib-devel>=%{nmver}
- BuildRequires:dbus-devel>=%{dbusver}
- BuildRequires:system-config-keyboard>=%{sckeyboardver}
- %ifarch%livearches
- BuildRequires:desktop-file-utils
- %endif
- BuildRequires:iscsi-initiator-utils-devel>=%{iscsiver}
- %ifarchs390s390x
- BuildRequires:s390utils-devel
- %endif
- Requires:python-meh>=%{mehver}
- Requires:policycoreutils
- Requires:rpm-python>=%{rpmpythonver}
- Requires:comps-extras
- Requires:parted>=%{partedver}
- Requires:pyparted>=%{pypartedver}
- Requires:yum>=%{yumver}
- Requires:libxml2-python
- Requires:python-urlgrabber>=3.9.1-5
- Requires:system-logos
- Requires:pykickstart>=%{pykickstartver}
- Requires:system-config-date>=%{syscfgdatever}
- Requires:device-mapper>=%{dmver}
- Requires:device-mapper-libs>=%{dmver}
- Requires:dosfstools
- Requires:e2fsprogs>=%{e2fsver}
- Requires:gzip
- Requires:xz
- Requires:libarchive
- %ifarch%{ix86}x86_64ia64
- Requires:dmidecode
- %endif
- Requires:python-pyblock>=%{pythonpyblockver}
- Requires:libuser-python
- Requires:newt-python
- Requires:authconfig
- Requires:system-config-firewall-base
- Requires:cryptsetup-luks
- Requires:python-cryptsetup>=%{pythoncryptsetupver}
- Requires:mdadm
- Requires:lvm2
- Requires:util-linux-ng>=2.15.1
- Requires:system-config-keyboard>=%{sckeyboardver}
- Requires:dbus-python
- Requires:cracklib-python
- Requires:python-nss
- Requires:tigervnc-server
- %ifarch%livearches
- Requires:usermode
- Requires:zenity
- %endif
- Requires:createrepo>=%{createrepover}
- Requires:squashfs-tools
- Requires:genisoimage>=%{genisoimagever}
- %ifarch%{ix86}x86_64
- Requires:syslinux>=3.73
- Requires:makebootfat
- Requires:device-mapper
- %endif
- %ifarchs390s390x
- Requires:openssh
- %endif
- Requires:isomd5sum
- Requires:yum-utils>=%{yumutilsver}
- Requires:NetworkManager>=%{nmver}
- Requires:dhclient
- Requires:anaconda-yum-plugins
- Requires:libselinux-python>=%{libselinuxver}
- Requires:fcoe-utils>=%{fcoeutilsver}
- %ifarch%{sparc}
- Requires:elftoaoutpiggyback
- %endif
- Obsoletes:anaconda-images<=10
- Provides:anaconda-images=%{version}-%{release}
- Obsoletes:anaconda-runtime<%{version}-%{release}
- Provides:anaconda-runtime=%{version}-%{release}
- Obsoletes:booty
- %description
- Theanacondapackagecontainstheprogramwhichwasusedtoinstallyour
- system.Thesefilesareoflittleuseonanalreadyinstalledsystem.
- %prep
- %setup-q
- %patch1000-p1
- %patch1001-p1
- %patch1002-p1
- %build
- %configure--disable-static
- %{__make}%{?_smp_mflags}
- %install
- %{__rm}-rf%{buildroot}
- %{__make}installDESTDIR=%{buildroot}
- find%{buildroot}-typef-name"*.la"|xargs%{__rm}
- %ifarch%livearches
- desktop-file-install--vendor=""--dir=%{buildroot}%{_datadir}/applications%{buildroot}%{_datadir}/applications/liveinst.desktop
- %else
- %{__rm}-rf%{buildroot}%{_bindir}/liveinst%{buildroot}%{_sbindir}/liveinst
- %endif
- %find_lang%{name}
- %clean
- %{__rm}-rf%{buildroot}
- %ifarch%livearches
- %post
- update-desktop-database&>/dev/null||:
- %endif
- %ifarch%livearches
- %postun
- update-desktop-database&>/dev/null||:
- %endif
- %files-f%{name}.lang
- %defattr(-,root,root)
- %docCOPYING
- %docdocs/command-line.txt
- %docdocs/install-methods.txt
- %docdocs/mediacheck.txt
- %docdocs/anaconda-release-notes.txt
- /lib/udev/rules.d/70-anaconda.rules
- %{_sbindir}/anaconda
- %ifarchi386i486i586i686x86_64
- %{_sbindir}/gptsync
- %{_sbindir}/showpart
- %endif
- %{_datadir}/anaconda
- %{_prefix}/lib/anaconda
- %{_prefix}/lib/anaconda-runtime
- %ifarch%livearches
- %{_bindir}/liveinst
- %{_sbindir}/liveinst
- %config(noreplace)%{_sysconfdir}/pam.d/*
- %config(noreplace)%{_sysconfdir}/security/console.apps/*
- %{_sysconfdir}/X11/xinit/xinitrc.d/*
- %{_datadir}/applications/*.desktop
- %{_datadir}/icons/hicolor/*
- %endif
- %changelog
- *SatJun232012KaranbirSingh<kbsingh@centos.org>-13.21.176.1.el6.centos
- -BuildforCentOS-6.3
三、总结
(1)IBM官方网站中rpm包的使用讲解的很全面,参看http://www.ibm.com/developerworks/cn/linux/management/package/rpm/part1/和rpmbuild的spec文件的解析参看http://www.ibm.com/developerworks/cn/linux/l-rpm/。
(2)rpm和rpmbuild内容众多丰富,该博客总结部分内容,以便使用时能快速查找到。
(3)若有读者想沟通交流的,可发信息到邮箱yang.ao@i-soft.com.cn。
热门推荐
- CentOS6.6中安装VNC server
- CentOS 6.6下安装GCC 4.8.2
- CentOS下ffmpeg与第三方编码编译安装
- centos安装jdk-从下载到正常运行
- centos6.6下安装GreenPlum4.3.5.2
- centos安装增强工具
- CentOS 6上部署OpenVPN Server
- 在CentOS6.5上安装Skype与QQ
- CentOS 7.1PXE网络自动化安装
- CentOS6.4 安装jenkins
- CentOS6.2安装配置 Mongodb3.0.4
- CentOS 6使用openssl搭建根CA
- CentOS 6.4安装配置squid
- CentOS 安装 Maven
- CentOS 安装SVN客户端
- centos 7 安装gamit和GMT
- CentOS安装配置openvpn使用ldap进行身份认证
- CentOS安装配置openvpn使用ldap进行身份认证
- 阿里云Centos6.5安装配置docker
- CentOS 6.6 x64搭建基于用户密码认证的openvpn