2011年1月5日 星期三

Debian Package Management - APT (Advanced Package Tool)

類別 : [TMLDP] [System Administration][Foundation]

1. Debian Package Manaement

        dpkg Debian 最基礎的套件管理工具,其它的Debian 衍生發行版,如Ubuntu
Knoppix都可以使用dpkg 來進行套件的管理。
但由於dpkg 並無法有效的處理套件相依性衝突的問題,故從Debian 2.1 Slink (1999)就出現了可以有效處理套件相依衝突的APT(Advanced Package Tool)供的工具來進行Debian 套件管理

        較常用的APT (Advanced Package Tool) 工具集工具如下 ,

  • apt-get : apt 所提供的套件安裝、移除、升級命令。
  • apt-cache : apt 所提供的套件查詢命令。
  • aptitude : Debian官方推薦的dpkg 套件管理前端工具程式,具有比apt更 好的套件相依衝突處理能力,除提供命令列操作介面外也提供了一個 文字視窗操作介面。
  • synaptic : Debian-Base 發行版最常見的圖形使用者介面視窗套件管理工具。


  2./etc/apt/apt.conf 

        APT的主設定檔是「/etc/apt/apt.conf」,主要是用來設定APT的相關屬性,例如設 定檔的所位置、主設定檔檔名、更新來源設定檔的檔名、下載的套件放置目錄...等。

3. /etc/apt/sources.list

/etc/apt/source.list』是apt 系統的套件來源設定檔,部分內容如下,
#deb cdrom:[Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)]/ lucid main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.


deb http://tw.archive.ubuntu.com/ubuntu/ lucid main restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid main restricted


## Major bug fix updates produced after the final release of the
## distribution.
deb http://tw.archive.ubuntu.com/ubuntu/ lucid-updates main restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid-updates main restricted


## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://tw.archive.ubuntu.com/ubuntu/ lucid universe
deb-src http://tw.archive.ubuntu.com/ubuntu/ lucid universe
.........

套件來源設定檔中的每一行都是用來描述一個套件來源,其語法如下

<DebType> <AddressType://Hostaddress/> <Distribution> <Section1> <Section2> <Section3>...

DebType : deb套件類別,『deb』 表示是二進位套件檔,『deb-src』表示是原始碼套件 檔。
AddressType : 連線位址類別,常見的有 httpftpfilecdromssh...等。

Distribution : 發行版名稱。

Section : 套件類別,如 stable testingmainrestricteduniversmultivers....等,可 時選擇一種以上的套件類別。

/etc/apt/source.list』的內容變更後需重新執行一次『apt-get update』以更新套 件索引清單。

4.apt-get

        APT提供了一個在命令列用來進行套件的安裝、移除與更新的工具-apt-get」其 語法如下,

        apt-get [Option] <command> [PackageName]

            常用選項如下,

            a. -y, --yes, --assume-yes : apt-get執行時提出詢問自動給與"YES"的答案。

        常用command:
        a. update : 更新本機有效套件索引清單

                變更『/etc/apt/source.list』的內容後或使用 APT 系列工具前,如
apt-get』、  『apt-cache』都應該先更新本機有效套件索引清單。

root@lab5:~# apt-get update
Hit http://tw.archive.ubuntu.com lucid Release.gpg
Hit http://tw.archive.ubuntu.com lucid-updates Release.gpg
Hit http://security.ubuntu.com lucid-security Release.gpg
Hit http://security.ubuntu.com lucid-security Release
Hit http://tw.archive.ubuntu.com lucid Release
Hit http://security.ubuntu.com lucid-security/main Packages
Hit http://tw.archive.ubuntu.com lucid-updates Release
Hit http://security.ubuntu.com lucid-security/restricted Packages
Hit http://security.ubuntu.com lucid-security/main Sources
Hit http://security.ubuntu.com lucid-security/restricted Sources
Hit http://security.ubuntu.com lucid-security/universe Packages
Hit http://security.ubuntu.com lucid-security/universe Sources
Hit http://tw.archive.ubuntu.com lucid/main Packages
Hit http://security.ubuntu.com lucid-security/multiverse Packages
Hit http://security.ubuntu.com lucid-security/multiverse Sources
Hit http://tw.archive.ubuntu.com lucid/restricted Packages
.....
Hit http://tw.archive.ubuntu.com lucid-updates/universe Packages
Hit http://tw.archive.ubuntu.com lucid-updates/universe Sources
Hit http://tw.archive.ubuntu.com lucid-updates/multiverse Packages
Hit http://tw.archive.ubuntu.com lucid-updates/multiverse Sources
Reading package lists... Done

        b. 安裝套件

               
apt-get install PackageName 



            
    
當需要下載套件時,apt-get 會詢問使用者是否要繼續執行。

        b. 移除套件

            與 dpkg 相同,apt-get 也提供了兩種不同的移除方式

              b-1.remove 移除套件,但保留設定檔

                   #apt-get remove PackageName

             b-2.purge 連同設定檔完整移除

                #apt-get purge PackageName

       c. upgrade : 更新系統所有已安裝套件到當前發行版版本最新狀態

          #apt-get upgrade
root@lab5:~# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
linux-generic linux-headers-generic linux-image-generic
The following packages will be upgraded:
acpi-support acpid app-install-data-partner apparmor apparmor-utils apt apt-transport-https
apt-utils aptdaemon at-spi avahi-autoipd avahi-daemon avahi-utils base-files bind9-host
binutils bogofilter bogofilter-bdb bogofilter-common brasero brasero-common byobu bzip2
capplets-data coreutils cups cups-bsd cups-client cups-common cups-driver-gutenprint
desktopcouch dmsetup dnsmasq-base dnsutils dpkg e2fslibs e2fsprogs empathy empathy-common
erlang-base erlang-crypto erlang-inets erlang-mnesia erlang-public-key erlang-runtime-tools
erlang-ssl erlang-syntax-tools erlang-xmerl evince evolution evolution-common
evolution-data-server evolution-data-server-common evolution-plugins f-spot fglrx-modaliases
file-roller firefox firefox-branding firefox-gnome-support gdebi gdebi-core gdm gedit
.......................
.......................
upstart ure ureadahead usb-creator-common usb-creator-gtk vinagre w3m wget xserver-common
xserver-xorg-core xulrunner-1.9.2
360 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Need to get 269MB of archives.
After this operation, 11.8MB of additional disk space will be used.
Do you want to continue [Y/n]?


        d.dist-upgrade : 發行版版本升級

           當發行版推出新版時,可以使用『apt-get dist-grade』將整個系統更新 到最新的發行版版本

              #apt-get dist-upgrade
root@lab5:~# apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
linux-headers-2.6.32-27 linux-headers-2.6.32-27-generic linux-image-2.6.32-27-generic
The following packages will be upgraded:
acpi-support acpid app-install-data-partner apparmor apparmor-utils apt apt-transport-https
apt-utils aptdaemon at-spi avahi-autoipd avahi-daemon avahi-utils base-files bind9-host
..............................
..............................
ttf-thai-tlwg tzdata ubufox ubuntu-system-service ubuntuone-client ubuntuone-client-gnome
udev udisks unattended-upgrades uno-libs3 update-inetd update-manager update-manager-core
upstart ure ureadahead usb-creator-common usb-creator-gtk vinagre w3m wget xserver-common
xserver-xorg-core xulrunner-1.9.2
363 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 312MB of archives.
After this operation, 197MB of additional disk space will be used.
Do you want to continue [Y/n]?



5.apt-chche

apt-cache 』可以用來查詢安裝套件名稱、套件相關訊息等資訊,其語法如下,

apt-cache [option] command [PackageName]

常用command如下,

a. showpkd : 顯示套件版本資訊及與其他套件的相依關係。
root@lab5:~# apt-cache showpkg joe
Package: joe
Versions:
3.7-1 (/var/lib/apt/lists/tw.archive.ubuntu.com_ubuntu_dists_lucid_universe_binary-i386_Packages)
Description Language:
File: /var/lib/apt/lists/tw.archive.ubuntu.com_ubuntu_dists_lucid_universe_binary-i386_Packages
MD5: 4d6bbc0d4cf8b71ec0b3dfa1ffb8ca46


2.9.8-1 (/var/lib/dpkg/status)
Description Language:
File: /var/lib/dpkg/status
MD5: 4d6bbc0d4cf8b71ec0b3dfa1ffb8ca46




Reverse Depends:
Dependencies:
3.7-1 - libc6 (2 2.4) libncurses5 (2 5.6+20071006-3)
2.9.8-1 - libc6 (2 2.3.2-1) libncurses5 (2 5.3.20030510-1)
Provides:
3.7-1 -
2.9.8-1 -
Reverse Provides:
b.show : 顯示套件完整資訊。
root@lab5:~# apt-cache show joe
Package: joe
Priority: optional
Section: universe/editors
Installed-Size: 1452
Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
Original-Maintainer: Josip Rodin <joy-packages@debian.org>
Architecture: i386
Version: 3.7-1
Depends: libc6 (>= 2.4), libncurses5 (>= 5.6+20071006-3)
Filename: pool/universe/j/joe/joe_3.7-1_i386.deb
Size: 480102
MD5sum: f6bf566629af078893eaf5dd64be042a
SHA1: 543e8b1f2343c02964b4357b7b66005662c5bf9e
SHA256: 7257bce2d680003e941b2eaa4516ee1376343512ab2702d27c10e62009bf2338
Description: user friendly full screen text editor
Joe, the Joe's Own Editor, has the feel of most PC text editors: the key
sequences are reminiscent of WordStar and Turbo C editors, but the feature
set is much larger than of those. Joe has all of the features a Unix
user should expect: full use of termcap/terminfo, complete VI-style Unix
integration, a powerful configuration file, and regular expression search
.....

c.stats : 顯示收集在cache 的套件相關統計
root@lab5:~# apt-cache status
E: Invalid operation status
root@lab5:~# apt-cache stats
Total package names: 39580 (1583k)
Normal packages: 30024
Pure virtual packages: 646
Single virtual packages: 2637
Mixed virtual packages: 296
Missing: 5977
Total distinct versions: 33064 (1852k)
Total distinct descriptions: 33064 (794k)
Total dependencies: 215836 (6043k)
Total ver/file relations: 35095 (562k)
Total Desc/File relations: 33064 (529k)
Total Provides mappings: 6127 (123k)
Total globbed strings: 150 (1992)
Total dependency version space: 1090k
Total slack space: 77.7k
Total space accounted for: 10.2M
d.search : 查詢安裝套件名稱

若需要確認安裝的套件名稱,可以使用
apt-cache search <PATTERN>』查詢,不過通常你會得到相當多輸出,可 以適當利用 grep 過濾無關的資訊。
root@lab5:~# apt-cache search ssh | grep -w 'ssh'
python-paramiko - Make ssh v2 connections with Python
ssh-import - import SSH public keys from Launchpad.net
clusterssh - administer multiple ssh or rsh shells simultaneously
dpsyco-ssh - Automate administration of access via ssh
gtk-led-askpass - GTK+ password dialog suitable for use with ssh-add
jta - Java telnet/ssh applet - documentation
jta-doc - Java telnet/ssh applet
ksshaskpass - interactively prompt users for a passphrase for ssh-add
libnet-ssh-gateway-ruby - Ruby library for tunneling connections to servers with ssh
libnet-ssh-gateway-ruby1.8 - Ruby library for tunneling connections to servers with ssh
libnet-ssh-gateway-ruby1.9.1 - Ruby library for tunneling connections to servers with ssh
libnet-ssh-perl - Perl extension for secure shell
libnet-ssh-ruby1.8 - pure ruby module that emulates an SSH client
libpam-ssh - Single sign-on via private SSH key
ssh-askpass - under X, asks user for a passphrase for ssh-add
ssh-askpass-fullscreen - Under Gnome2, asks user for a passphrase for ssh-add
sshguard - Protects from brute force attacks against ssh
sshm - A command-line tool to manage your ssh servers
sshpass - Non-interactive ssh password authentication
sslh - ssl/ssh multiplexer
zssh - interactive file transfers over ssh
ssh - secure shell client and server (metapackage)
ssh-askpass-gnome - interactive X program to prompt users for a passphrase for ssh-add
erlang-ssh - Erlang/OTP implementation of SSH protocol
ssh-krb5 - secure shell client and server (transitional package)
root@lab5:~#

e.depends : 查詢指定檔案或指定套件的相依套件
root@lab5:~# apt-cache depends ssh
ssh
Depends: openssh-client
Depends: openssh-server
root@lab5:~# apt-cache depends joe
joe
Depends: libc6
Depends: libncurses5

root@lab5:~# apt-cache depends openssh-client
openssh-client
Depends: libc6
Depends: libedit2
Depends: libgssapi-krb5-2
Depends: libssl0.9.8
Depends: zlib1g
|Depends: debconf
Depends: <debconf-2.0>
cdebconf
debconf
Depends: adduser
Depends: dpkg
Depends: passwd
Suggests: ssh-askpass
gtk-led-askpass
ksshaskpass
ssh-askpass-fullscreen
ssh-askpass-gnome
Suggests: libpam-ssh
Suggests: keychain
Suggests: openssh-blacklist
Suggests: openssh-blacklist-extra
Recommends: xauth
Conflicts: rsh-client
Conflicts: <sftp>
Conflicts: ssh
Conflicts: ssh-krb5
Replaces: ssh
Replaces: ssh-krb5
root@lab5:~#
6.apt-cdrom

若需要將光碟當成更新來源,可以使用apt-cdrom add 』將光碟的設定項加入 /etc/apt/source.list』中,奇語法如下,

#apt-cdrom add
root@lab5:~# apt-cdrom add
Using CD-ROM mount point /media/apt/
Identifying.. [d00480f76f2d81dbf30817849c039fdc-2]
Scanning disc for index files..
Found 2 package indexes, 0 source indexes, 0 translation indexes and 1 signatures
This disc is called:
'Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)'
Copying package lists...gpgv: Signature made Thu Apr 29 20:56:05 2010 CST using DSA key ID FBB75451
gpgv: Good signature from "Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>"
Reading Package Indexes... Done
Writing new source list
Source list entries for this disc are:
deb cdrom:[Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)]/ lucid main restricted
Repeat this process for the rest of the CDs in your set.
W: Skipping nonexistent file /media/apt/dists/lucid/main/binary-i386/Packages
W: Skipping nonexistent file /media/apt/dists/lucid/restricted/binary-i386/Packages
root@lab5:~#

完成後,在/etc/apt/source.list』中就會多出一行以cd-rom 作為更新來源的設定 項。

root@lab5:~# cat /etc/apt/sources.list | grep cdrom | grep -v "^#"
deb cdrom:[Ubuntu 10.04 LTS _Lucid Lynx_ - Release i386 (20100429)]/ lucid main restricted

若需確認光碟完整性可以使用apt-cdrom ident』進行掃描。



            

沒有留言:

張貼留言

Powered By Blogger