Linux程式包管理

來源:互聯網
上載者:User

標籤:yum   rpm   

Rpm包簡介

Rpm包就是在相對應的作業系統平台上面編譯好的軟體包,沒有編譯之前就是一堆的原始碼,很多剛接觸Linux的使用者還沒有能力或自行編譯原始碼程式的難度很大,所以才會有了rpm包管理器。使用rpm可以使使用者方便的進行軟體的安裝、查詢、卸載、升級等工作。但是rpm軟體包之間的依賴性問題往往會很繁瑣,尤其是軟體由多個rpm包組成時。

 

程式編譯之後一般有四個部分組成,二進位程式,庫檔案,設定檔,協助檔案下面分別列出了這些檔案在系統的存放路徑。

二進位程式:/bin, /sbin, /usr/bin, /usr/sbin,/usr/local/bin, /usr/local/sbin, /opt/bin, /opt/sbin

庫檔案:/lib, /lib64, /usr/lib, /usr/lib64,/usr/local/lib, /usr/local/lib64

設定檔:/etc, /etc/DIR, /usr/local/{etc,conf}

協助檔案:/usr/share/man, /usr/share/doc,/usr/local/share/man

 

原始碼包在編譯時間可以對程式包的功能進行定製,需要的功能可以編譯,不需要的功能就不編譯。但是rpm包是直接編譯好的程式包,為了使使用者能夠在安裝的時候選擇需要的功能,捨棄不需要的功能,就會對一個程式進行分包,一個程式就會被編譯成多個功能不同的包,讓使用者選擇安裝。

程式包的命名方式

appname-VERSION-RELEASE.ARCH.rpm

    VERSION:

       major:主要版本號

       minor:次版本號碼

       release:發行號

    RELEASE:包自身的修訂編號;有時候還會包含適用於的OS資訊;比如bash-4.3.2-2.centos6.x86_64.rpm中的2.centos6

    ARCH:適用的平台

       x86:i386, i486, i586, i686

       x86_64:x86_64, amd64

       powerpc:ppc

       noarch:跟平台無關;

httpd軟體包的命名方式如下:

httpd-2.2.15-39.el6.centos.x86_64.rpm

rpm包的來源

1、系統的安裝光碟片或官方鏡像網站

掛載光碟片:mount /dev/cdrom /media/cdrom

    官方網站,鏡像:

       mirrors.sohu.com

       mirrors.163.com

       mirrors.aliyun.com

2、程式包的官方網站

3、第三方組織:epel

4、搜尋引擎

    http://rpmfind.net

    http://rpm.pbone.net

    http://pkgs.org

rpm軟體包管理安裝軟體包

文法:rpm {-i|--install}{install-options}軟體包

選項:

    -i:表示安裝軟體包,--install是長選項

-h:以#來表示安裝進度

-v:顯示安裝過程中的詳細資料

-vv:顯示更詳細的資訊

-vvv:顯示比vv還詳細的資訊

--test:不執行真正的安裝過程,而僅報告衝突資訊

--nodeps:忽略依賴關係。雖然可以安裝成功,但是未必可以正常運行。

--force:強制安裝軟體包。

   --replacepkgs:覆蓋安裝,重新安裝並覆蓋原有檔案。

--relocate:把允許修改安裝路徑的程式包的安裝路徑定位到新路徑下

--replacefiles:有多個程式包安裝時,可能安裝相同的檔案,這時需要指定後安裝的程式包替換前面程式包安裝的檔案

安裝時常用的組合:-ivh,-ivvh

執行個體:安裝zsh軟體

[[email protected] Packages]# rpm -ivh zsh-4.3.10-7.el6.x86_64.rpmwarning: zsh-4.3.10-7.el6.x86_64.rpm: Header V3RSA/SHA1 Signature, key ID c105b9de: NOKEYPreparing...               ########################################### [100%]   1:zsh                   ########################################### [100%]

依賴關係:rpm包最kengdie的地方就是安裝a軟體包,可能依賴b,安裝b依賴c,有時候一個封裝到最後依賴幾十個上百個都說不定。

解決依賴關係安裝軟體包

[[email protected] Packages]# rpm -ivh php-5.3.3-38.el6.x86_64.rpmwarning: php-5.3.3-38.el6.x86_64.rpm: Header V3RSA/SHA1 Signature, key ID c105b9de: NOKEYerror: Failed dependencies:       php-cli(x86-64) = 5.3.3-38.el6 is needed by php-5.3.3-38.el6.x86_64         php-common(x86-64) = 5.3.3-38.el6 is needed by php-5.3.3-38.el6.x86_64

上面的錯誤提示表示安裝php依賴與php-cli軟體包和php-common軟體包,只需要一起安裝就不會報錯了

[[email protected] Packages]# rpm -ivh php-5.3.3-38.el6.x86_64.rpm php-cli-5.3.3-38.el6.x86_64.rpm php-common-5.3.3-38.el6.x86_64.rpm
升級軟體包:

文法:rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...

   -U:升級或安裝(如果有就升級,沒有就安裝)

  rpm{-F|--freshen} [install-options] PACKAGE_FILE ...

       -F:升級(如果此前沒有安裝低版本軟包,那麼就不會執行升級操作)

選項:

--test:只是測試是否可以升級,而不是正正升級。

--nodeps:升級時忽略依賴關係

--force:強制升級

--oldpackage:程式包降級

--relocate:把允許修改安裝路徑的程式包的安裝路徑定位到新路徑下

--replacefiles:安裝時只替換指定檔案

常用組合:-Uvh,-Fvh

注意:

(1)一定不要對核心執行升級,新版核心可能對系統不相容。

      Linux允許多核心共存,所以,可以直接安裝多個不同版本的核心;

(2)如果程式包的設定檔安裝後曾被修改,升級時,新版本的檔案不會覆蓋老版本的設定檔,而把新版本的設定檔重新命名(加尾碼.rpmnew)後儲存。

樣本:升級zsh,下載到新版的zsh之後將軟體包直接執行下面的升級命令即可

[[email protected] ~]# rpm -Uvh zsh-4.3.10-8.el6_5.x86_64.rpm

新版zshhttp://mirrors.aliyun.com/centos/6.6/updates/x86_64/Packages/

卸載:

文法:rpm  {-e|--erase}   [--allmatches]   [--nodeps]  [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...

簡單用法:

rpm –e PACKAGE_NAME

--nodeps:忽略依賴關係

--test:測試卸載

--allmatches:如果一個程式包同時安裝多個版本,則此選項一次全部卸載之。

注意:如果程式包的設定檔安裝後曾被修改,卸載時,此檔案通常不會被刪除,而是被重新命名(加尾碼,rpmsave)後留存;

樣本:卸載zsh

[[email protected] ~]# rpm -e zsh

卸載的時候只需要對軟體包名執行卸載命令即可,不需要更版本和尾碼等資訊,那樣反而會報錯。

查詢:

查詢某包是否已經安裝,以及檢查安裝的所有包;還可以查看某包的詳細資料

文法:rpm {-q|--query} [select-options] [query-options]

[select-options]選項說明:

1.查詢某包或某些包是否安裝;

rpm –q PACKAGE_NAME

樣本:查詢是否已經安裝httpd,查詢結果會輸出httpd的完整包名。

[[email protected] Packages]# rpm -q httpdhttpd-2.2.15-39.el6.centos.x86_64

2.查詢已經安裝的所有包;

rpm –qa

說明:如果查看已經安裝的所有包的話,輸出的結果會很龐大,一般使用此選項常用的功能有兩種

(1)查詢當前系統安裝了多少rpm包

樣本:查詢當前系統安裝了多少軟體包

[[email protected] ~]# rpm -qa | wc -l1032

(2)將查詢結果使用grep過濾,查看有多少匹配的軟體包

樣本:查詢當前系統安裝的httpd相關軟體包的資訊

[[email protected] ~]# rpm -qa | grep httpdhttpd-tools-2.2.15-39.el6.centos.x86_64httpd-2.2.15-39.el6.centos.x86_64

3.查詢某檔案是由那個包安裝產生的

rpm –qf

樣本:查詢/etc/httpd/conf/httpd.conf是由那個軟體包安裝的。

[[email protected] ~]# rpm -qf/etc/httpd/conf/httpd.confhttpd-2.2.15-39.el6.centos.x86_64

4.查詢尚未安裝包的資訊

-p

     說明:-p選項 不能單獨使用,需要結合[query-options]參數一起使用。

樣本:查詢mysql軟體包的相關資訊

[[email protected] Packages]# rpm -pqimysql-5.1.73-3.el6_5.x86_64.rpmwarning: mysql-5.1.73-3.el6_5.x86_64.rpm: Header V3RSA/SHA1 Signature, key ID c105b9de: NOKEYName        :mysql                        Relocations:(not relocatable)Version     :5.1.73                            Vendor: CentOSRelease     :3.el6_5                       Build Date:Thu 13 Feb 2014 03:42:39 AM CSTInstall Date: (not installed)               Build Host:c6b9.bsys.dev.centos.orgGroup       :Applications/Databases        Source RPM:mysql-5.1.73-3.el6_5.src.rpmSize        :2495591                          License:GPLv2 with exceptionsSignature   :RSA/SHA1, Thu 13 Feb 2014 03:48:07 AM CST, Key ID 0946fca2c105b9dePackager    :CentOS BuildSystem <http://bugs.centos.org>URL         : http://www.mysql.comSummary     :MySQL client programs and shared librariesDescription :MySQL is a multi-user, multi-threaded SQL databaseserver. MySQL is aclient/server implementation consisting of a serverdaemon (mysqld)and many different client programs and libraries.The base packagecontains the standard MySQL client programs andgeneric MySQL files.

參數說明:

Name:軟體名

Version:版本資訊

Release:發行號

Install Date:包的安裝時間

Group:包所在的組

Size:大小

Signature:包的簽名資訊

Packager:包的製作人

URL:包的原始碼程式可以從那裡擷取到

Summary:包的簡要介紹

Relocations:是否被重新置放到其他位置

Vendor:供應商

Build Date:包的構建時間

Build Host:編譯包的主機

Source RPM:源rpm包

License:許可證

Description:包的詳細介紹

 

[query-options]選項說明:

1.查詢某包的簡要資訊

rpm -qi

2.查詢某包安裝產生的檔案清單

rpm –ql

樣本:顯示安裝httpd產生的檔案清單,

[[email protected] Packages]# rpm -ql httpd/etc/httpd/etc/httpd/conf/etc/httpd/conf.d/etc/httpd/conf.d/README/etc/httpd/conf.d/welcome.conf/etc/httpd/conf/httpd.conf/etc/httpd/conf/magic/etc/httpd/logs/etc/httpd/modules/etc/httpd/run……產生列表過多,省略部分內容……


3.查詢某包安裝完成後的所有設定檔

rpm –qc

樣本:顯示php安裝完成之後的設定檔。

[[email protected] ~]# rpm -qc php/etc/httpd/conf.d/php.conf

4.查詢某包安裝完成後的協助檔案

rpm –qd

[[email protected] ~]# rpm -qd httpd/usr/share/doc/httpd-2.2.15/ABOUT_APACHE/usr/share/doc/httpd-2.2.15/CHANGES/usr/share/doc/httpd-2.2.15/LICENSE/usr/share/doc/httpd-2.2.15/NOTICE/usr/share/doc/httpd-2.2.15/README/usr/share/doc/httpd-2.2.15/VERSIONING/usr/share/man/man8/apachectl.8.gz/usr/share/man/man8/htcacheclean.8.gz/usr/share/man/man8/httpd.8.gz/usr/share/man/man8/rotatelogs.8.gz/usr/share/man/man8/suexec.8.gz

5.查看某包製作時隨版本變化的changelog資訊,changelog記錄了包的每次更新都做了什麼改動

rpm –q –changelog

[[email protected] ~]# rpm -q -changelog httpd* Wed Oct 15 2014 Johnny Hughes<[email protected]> - 2.2.15-39.el6.centos- Roll in CentOS Branding * Tue Aug 05 2014 Jan Kaluza <[email protected]>- 2.2.15-39- mod_proxy: close client connection if the backendcloses connection (#1111410)……輸出內容過多,省略部分內容……

6.查詢某包提供的capabilities,

rpm –q –provides

[[email protected] ~]# rpm -q -provides httpdconfig(httpd) = 2.2.15-39.el6.centoshttpd-mmn = 20051115httpd-suexec = 2.2.15-39.el6.centosmod_actions.so()(64bit) mod_alias.so()(64bit) mod_asis.so()(64bit) mod_auth_basic.so()(64bit) ……輸出內容過多,省略部分內容……

7.查詢某包所依賴的capabilities

rpm –q –requires

[[email protected] ~]# rpm -q -requires httpd/bin/bash /bin/sh /etc/mime.types /usr/sbin/useradd apr-util-ldap chkconfig config(httpd) = 2.2.15-39.el6.centoshttpd-tools = 2.2.15-39.el6.centos……輸出內容過多,省略部分內容……

8.查詢某包安裝卸載時執行的指令碼

rpm –q –scripts

指令碼有四類:

preinstall:安裝過程開始之前執行的指令碼

postinstall:安裝過程完成之後執行的指令碼

prenuinstall:卸載開始之前執行的指令碼

postuninstall:卸載過程完成之後執行的指令碼

[[email protected] ~]# rpm -q -scripts httpdpreinstall scriptlet (using /bin/sh):   #表示安裝前指令碼# Add the "apache" usergetent group apache >/dev/null || groupadd -g 48-r apachegetent passwd apache >/dev/null ||   useradd -r-u 48 -g apache -s /sbin/nologin     -d/var/www -c "Apache" apacheexit 0postinstall scriptlet (using /bin/sh): #表示安裝後指令碼# Register the httpd service/sbin/chkconfig --add httpd/sbin/chkconfig --add htcachecleanpreuninstall scriptlet (using /bin/sh): #卸載前執行的指令碼if [ $1 = 0 ]; then       /sbin/service httpd stop > /dev/null 2>&1       /sbin/chkconfig --del httpd       /sbin/service htcacheclean stop > /dev/null 2>&1       /sbin/chkconfig --del htcachecleanfiposttrans scriptlet (using /bin/sh):    #卸載完成執行之後執行的指令碼test -f /etc/sysconfig/httpd-disable-posttrans ||  /sbin/service httpd condrestart >/dev/null2>&1 || :


本文出自 “梅花香自苦寒來” 部落格,請務必保留此出處http://ximenfeibing.blog.51cto.com/8809812/1631436

Linux程式包管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.