Linux軟件包管理

    Linux中軟件包大致可以分爲兩類:源碼包和二進制包。

    其中源碼包是由C語言編寫的開源(可修改)的軟件包。源碼包在編譯安裝時可以自由選擇功能,卸載時可直接方便刪除即可,因爲它是編譯安裝的,所安裝的軟件可以更兼容本機的硬件平臺,更加穩定高效。但是源碼包編譯安裝安裝大型軟件集合時步驟繁瑣容易出錯。

    二進制包也叫RPM包,它安裝方便,通常一個命令就可以搞定一個軟件,但是它是經過編譯的,看不到源碼,更不能進行修改,而且它最大的缺點是安裝軟件必須解決軟件包的依賴關係,yum在線安裝解決了這個棘手問題。

源碼包的安裝

    源碼包安裝在指定位置,一般是/usr/local/software_name/,跟rpm安裝在默認的位置不同的是所安裝的服務不能通過服務管理器設別,只能用絕對路徑管理服務。

    安裝源碼包因爲需要編譯所以要先在linux中安裝C語言編譯器GCC。

    解壓縮源碼包(源碼包一般放在/usr/local/scr/中),進入解壓縮目錄開始安裝。

    安裝前先看一下INSTALL文件和README文件。

    1、.configure  #軟件的配置和檢查,並將定義好的功能和系統環境的信息寫入Makefile文件中

    2、make  #編譯

    3、make install  #編譯安裝

    

RPM軟件包安裝

rpm命令安裝

    rpm包的包名格式一般是【名字-版本-發行號-平臺.rpm】

    rpm包還有二進制格式和源碼格式,源碼格式跟源碼包一樣在本機編譯,能更好發揮本機的硬件性能。  

安裝:

rpm  -ivh /path/包全名

  選項

    -i        #install安裝 

    -v        #verbose 顯示詳細信息(-vv)

    -h        #hash 顯示進度,以#顯示進度,每個#表示2%

    --replacepkgs #重新安裝,替換原有安裝

    --force       #強行安裝,可以實現重裝或降級

    - - nodeps    #不檢測依賴性

升級:

rpm  -Uvh /path/包全名   

    -U         #升級軟件

卸載:

rpm  -e  包名

  -e    erase 卸載

  - - nodeps  不檢查依賴性

查詢:

  1.查詢是否安裝

    rpm  -q  包名        query是否安裝

    rpm -qa  包名        查詢所有已經安裝的rpm包

[root@localhost ~]# rpm -q screen     
screen-4.0.3-4.el5
[root@localhost ~]# rpm -qa | head
rmt-0.4b41-4.el5
desktop-backgrounds-basic-2.0-37
man-pages-2.39-15.el5
popt-1.10.2.3-18.el5
libusb-0.1.12-5.1
readline-5.1-3.el5
bzip2-libs-1.0.3-4.el5_2
gdbm-1.8.0-26.2.1
elfutils-libelf-0.137-3.el5
libfontenc-1.0.2-2.2.el5

  2.查詢軟件包詳細信息

    rpm -qi  包名 

      -i      information查詢軟件信息

      -p     package  查詢未安裝包信息

[root@localhost ~]# rpm -qi screen
Name        : screen                       Relocations: (not relocatable)
Version     : 4.0.3                             Vendor: CentOS
Release     : 4.el5                         Build Date: 2011年05月04日 星期三 23時29分00秒
Install Date: 2015年10月25日 星期日 05時17分39秒      Build Host: builder10.centos.org
Group       : Applications/System           Source RPM: screen-4.0.3-4.el5.src.rpm
Size        : 757243                           License: GPL2
Signature   : DSA/SHA1, 2011年05月05日 星期四 01時13分55秒, Key ID a8a447dce8562897
URL         : http://www.gnu.org/software/screen
Summary     : 在一個終端機上支持多重登錄的屏幕管理器。
Description :
screen 工具允許您在一個終端機上有多重登錄。
screen 對於遠程登錄到一個機器上或通過一個簡單
終端來連接的,但又想有多個登錄的用戶來說
很有用處。

如果您需要一個能夠支持在一個終端機上的多重
登錄的屏幕管理器,請安裝 screen 軟件包。

  3.查詢包中文件呢安裝位置

    rpm -ql 包名

      -l   list 列表

      -p     package  查詢未安裝包信息

[root@localhost ~]# rpm -q screen
screen-4.0.3-4.el5
[root@localhost ~]# rpm -ql screen
/etc/pam.d/screen
/etc/screenrc
/usr/bin/screen
/usr/share/doc/screen-4.0.3
/usr/share/doc/screen-4.0.3/FAQ
/usr/share/doc/screen-4.0.3/NEWS
/usr/share/doc/screen-4.0.3/README
/usr/share/doc/screen-4.0.3/README.DOTSCREEN
/usr/share/info/screen.info.gz
/usr/share/man/man1/screen.1.gz
/usr/share/screen
/usr/share/screen/utf8encodings
/usr/share/screen/utf8encodings/01
/usr/share/screen/utf8encodings/02
/usr/share/screen/utf8encodings/03
/usr/share/screen/utf8encodings/04
/usr/share/screen/utf8encodings/18
/usr/share/screen/utf8encodings/19
/usr/share/screen/utf8encodings/a1
/usr/share/screen/utf8encodings/bf
/usr/share/screen/utf8encodings/c2
/usr/share/screen/utf8encodings/c3
/usr/share/screen/utf8encodings/c4
/usr/share/screen/utf8encodings/c6
/usr/share/screen/utf8encodings/c7
/usr/share/screen/utf8encodings/c8
/usr/share/screen/utf8encodings/cc
/usr/share/screen/utf8encodings/cd
/usr/share/screen/utf8encodings/d6
/var/run/screen

  4.查詢系統文件屬於哪個rpm包

    rpm -qf  系統文件名

      -f   file查詢系統文件屬於哪個軟件包


  5.查詢軟件包的依賴性

    rpm  -qR  包名

      -R 查詢軟件包的依賴性requires

[root@localhost ~]# rpm -qR screen
/bin/sh  
/bin/sh  
/bin/sh  
/sbin/install-info  
/sbin/install-info  
/usr/sbin/groupadd  
config(screen) = 4.0.3-4.el5
libc.so.6  
libc.so.6(GLIBC_2.0)  
libc.so.6(GLIBC_2.1)  
libc.so.6(GLIBC_2.2)  
libc.so.6(GLIBC_2.3.4)  
libc.so.6(GLIBC_2.4)  
libcrypt.so.1  
libcrypt.so.1(GLIBC_2.0)  
libncurses.so.5  
libpam.so.0  
libpam.so.0(LIBPAM_1.0)  
libutempter.so.0  
libutil.so.1  
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rtld(GNU_HASH)

RPM包校驗:

  rpm -V 已安裝的包名

    -V   校驗指定RPM包中的文件verify

    驗證內容包括文件大小(S)、文件的類型或文件的權限rwx(M)、文件的MD5校驗和(5)、設備的代碼(D)、文件路徑(L)、文件的屬主(所有者U)、屬組(G)、文件的修改時間(T)、對應位置沒有被修改過 (T)。


RPM包中文件提取:

  rpm2cpio  包全名 | cpio  -idv    .文件絕對路徑

  將rpm包轉換爲cpio格式



yum命令安裝

常用命令

查看配置文件/etc/yum.repos.d/CentOS-Base.repo(查看網絡yum源)

[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo 
[base]  #容器名稱
name=CentOS-5 - Base   #容器說明
baseurl=  #yum源服務器地址 
gpgcheck=1  #RPM數字證書生效與否(1爲生效)
gpgkey=  #數字證書的公鑰文件保存位置

#released updates
[update]
name=CentOS-5 - Updates
baseurl=http://centos.ustc.edu.cn/centos/5/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-5 - Addons
baseurl=http://centos.ustc.edu.cn/centos/5/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
#additional packages that may be useful
[extras]
name=CentOS-5 - Extras
baseurl=http://centos.ustc.edu.cn/centos/5/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-5 - Plus
baseurl=http://centos.ustc.edu.cn/centos/5/centosplus/$basearch/
gpgcheck=1
enabled=0   #容器生效與否,不寫或=1爲生效,=0爲不生效
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-5 - Contrib
baseurl=http://centos.ustc.edu.cn/centos/5/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages in testing
[testing]
name=CentOS-5 - Testing
baseurl=http://centos.ustc.edu.cn/centos/5/testing/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

查詢所有可用軟件包列表:

[root@localhost ~]# yum list | head
Loading mirror speeds from cached hostfile
Installed Packages
Deployment_Guide-en-US.noarch            5.2-11                        installed
Deployment_Guide-zh-CN.noarch            5.2-11                        installed
Deployment_Guide-zh-TW.noarch            5.2-11                        installed
GConf2.i386                              2.14.0-9.el5                  installed
GConf2-devel.i386                        2.14.0-9.el5                  installed
ImageMagick.i386                         6.2.8.0-4.el5_1.1             installed
MAKEDEV.i386                             3.23-1.2                      installed


Exiting on Broken Pipe

搜索服務器上匹配到的包

[root@localhost ~]# yum search gimp
Loading mirror speeds from cached hostfile
================================= Matched: gimp =================================
glib-devel.i386 : The GIMP ToolKit (GTK+) and GIMP Drawing Kit (GDK) support
                : library.
gtk+.i386 : The GIMP ToolKit (GTK+), a library for creating GUIs for X.
gtk+-devel.i386 : Development tools for GTK+ (GIMP ToolKit) applications.
gimp.i386 : GNU Image Manipulation Program
gimp-devel.i386 : GIMP 插件和擴展開發工具包
gimp-libs.i386 : GIMP libraries
gimp-data-extras.noarch : GIMP 的附加文件。
gimp-help.noarch : GIMP 的幫助文件。
gimp-print.i386 : 一組高質量的打印機驅動程序集合。
gimp-print-cups.i386 : 用於 Canon、Epson、HP 及兼容打印機的 CUPS 驅動程序
gimp-print-devel.i386 : 開發使用 gimp-print 的應用程序所需的文件。
gimp-print-plugin.i386 : 用於 gimp-print 的 GIMP 插件
gimp-print-utils.i386 : gimp-print 的工具程序
glib2-devel.i386 : GIMP 工具包 (GTK+) 和 GIMP 繪圖包 (GDK) 支持庫。
gtk2.i386 : The GIMP ToolKit (GTK+), a library for creating GUIs for X
xsane-gimp.i386 : 一個提供 SANE 掃描儀接口的 GIMP 插件。

yum源安裝/升級/卸載(-y 自動進行)

[root@localhost ~]# yum -y install screen

[root@localhost ~]# yum -y update screen  #必須指定包名,不然linux會全部升級(包括內核,但是內核不能yum升級)

[root@localhost ~]# yum -y remove screen  #yum卸載會卸載很多系統相關的軟件,很危險


yum軟件組管理

yum  grouplist                 #列出所有可用的軟件組列表

yum  groupinstall              #軟件組名 安裝指定軟件組,組名可以由grouplist查詢出來

yum  groupremove  軟件組名     #卸載指定軟件組

[root@localhost ~]# yum grouplist
Setting up Group Process
Loading mirror speeds from cached hostfile
Installed Groups:
   GNOME 桌面環境
   X 窗口系統
   X 軟件開發
   Yum Utilities
   萬維網服務器
   辦公/生產率
   圖形
   圖形化互聯網
   基於文本的互聯網
   開發工具
   開發庫
   打印支持
   撥號聯網支持
   授權和出版
   服務器配置工具
   遊戲和娛樂
   管理工具
   系統工具
   編輯器
   網絡服務器
   老的網絡服務器
   老的軟件開發
   老的軟件支持
   視頻和音頻
   郵件服務器
Available Groups:
   Beagle
   DNS 名稱服務器
   Eclipse
   FTP 服務器
   FreeNX and NX
   GNOME 軟件開發
   Horde
   HyperV
   Java開發
   KDE 軟件開發
   KDE (K 桌面環境)
   Mono
   MySQL 數據庫
   OpenFabrics 企業版發行
   PostgreSQL 數據庫
   Tomboy
   Windows 文件服務器
   XFCE-4.4
   Xen
   基本
   工程和科學
   新聞服務器
   集羣
   集羣存儲
Done

光盤yum源搭建

掛載光盤 mount  /dev/cdrom  /mnt/cdrom

讓網絡yum源文件失效(把.repo改成.repo.bak)

修改光盤yum源文件

    [root@xxx  yum.repos.d]#  vim  CentOS-Media.repo
    [c6-media]
    name=CentOS-$releasever - Media
    baseurl=file:///mnt/cdrom     #地址改爲光盤掛載地址
    #註釋掉兩個不存在的地址: 
    #    file:///media/cdrom/ 
    #    file:///media/cdrecorder
    gpgcheck=1 #值改爲1
    enabled=1  #值改爲1使yum源配置文件生效
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS -6  #不用修改

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章