FlossDoc: 請協力 GPLv3 的中文翻譯工作。

使用 APT 管理套件

FlossDoc,自由中文開源知識庫

Jump to: navigation, search

標準文章
作者: Roy Chan
協力: Anthony Wong, Reno
校對: -
級別: 初階
分享本文:
APT 圖像介面前端 Synaptic
Enlarge
APT 圖像介面前端 Synaptic

DebianUbuntuKubuntuXubuntuXandros 使用由 Debian 發簡化軟件套件管理的 APT (Advanced Packaging Tools)。APT 讓使用者可以輕地搜尋、下載、安裝和升級在網上、硬碟或光碟上軟件庫中的套件,並在安裝、升級和移除時,自動找出所有額外需要同時安裝、升級或移除的相依套件,令軟件管理變得簡易非常。

除了一些圖像介面工具如 SynapticAdept 等外,最直接輕便快捷使用 APT 管理套件的方法自然是 apt-get 和 apt-cache 命令。

目录

基本設定

設定 APT 套件庫列表

檔案 /etc/apt/sources.list ,其格式為:

類型 URI 發行版本 組別...
  • 類型 - dpkg 系統 (Debian 等) 會是 "deb" 或 "deb-src",RPM 系統 (Fedora, RedHat 等) 則會是 "rpm" 或 "rpm-src":
    • deb : 表示這個 APT 套件庫收藏了 dpkg 套件。
    • deb-src : 表示這個 APT 套件庫收藏了 dpkg 套件的源碼,即 *.orig.tar.gz 、 *.dsc 及 *.diff.gz 三個檔。
    • rpm : 表示這個 APT 套件庫收藏了 RPM 套件。
    • rpm-src : 表示這個 APT 套件庫收藏了 SRPM 套件。
  • URI - 表示 APT 伺服器的位址及使用協定
    • http://apt.example.com - 透過 HTTP 拿取套件
    • ftp://ftp.example.com - 透過 FTP 拿取套件
    • cdrom:[Debian GNU/Linux 3.0 (woody) - Bonzai Linux]/ - 由 CD-ROM 拿取套件
    • file:///var/ftp/debian/ - 直接從本地檔案系統拿取套件
  • 發行版本 (Distribution): e.g. stable, unstable, sid
  • 組別 (Section): main, contrib, non-free

Debian 例子:

deb http://ftp.hk.debian.org/debian/ stable main contrib non-free
# deb-src http://ftp.hk.debian.org/debian/ stable main contrib non-free
deb http://ftp.hk.debian.org/debian-non-US/ stabe/non-US main contrib non-free
# deb-src http://ftp.hk.debian.org/debian-non-US/ stabe/non-US main contrib non-free

deb http://security.debian.org/ stable/updates main contrib non-free

Red Hat 例子:

# Red Hat Linux 9
rpm http://ayo.freshrpms.net redhat/9/i386 os updates freshrpms
# rpm-src http://ayo.freshrpms.net redhat/9/i386 os updates freshrpms

設定 Proxy 伺服器

Apt 允許你設定 proxy 伺服器。如果你有這個需要,你可以修改檔案 /etc/apt/apt.conf ,在 Acquire 裡的 Http 加入 Proxy 項目:  

Acquire
{
  Http
  {
    Proxy "http://proxy.example.com:3128";
  };
  Retries "0";
};

  你亦可以使用簡短的寫法:

//加在最後一行,注意不要被括號 {} 括住了!
Acquire::Http::Proxy "http://proxy.example:3128";

搜尋/安裝/移除套件

更新軟件庫套件資料 (apt-get update)

為加快套件管理工作的速度,APT 會把各軟件庫的套件資料暫存在電腦中。而所有套件搜尋、安裝和更新工作都是根據暫存在電腦的軟件庫套件資料複本進行。然而過久未有更新軟件庫套件資料,可能會和網上的版本有差異。所以每一般時間都應該使用 “apt-get update” 命更新所有軟件庫的套件資料:

# apt-get update
下載:1 ftp://ftp.hk.debian.org stable/main Packages [3577kB]
已有 http://deb.opera.com stable/non-free Packages
略過 http://deb.opera.com stable/non-free Release
下載:2 ftp://ftp.hk.debian.org stable/main Release [82B]
已有 ftp://ftp.hk.debian.org stable/non-free Packages
下載:3 ftp://ftp.hk.debian.org stable/non-free Release [86B]
已有 ftp://ftp.hk.debian.org stable/contrib Packages
下載:4 ftp://ftp.hk.debian.org stable/contrib Release [85B]
已有 ftp://ftp.hk.debian.org stable/non-US/main Packages
已有 ftp://ftp.hk.debian.org stable/non-US/main Release
已有 ftp://ftp.hk.debian.org stable/non-US/non-free Packages
已有 ftp://ftp.hk.debian.org stable/non-US/non-free Release
已有 ftp://ftp.hk.debian.org stable/non-US/contrib Packages
已有 ftp://ftp.hk.debian.org stable/non-US/contrib Release
下載:5 ftp://ftp.hk.debian.org stable/main Sources [1415kB]
下載:6 ftp://ftp.hk.debian.org stable/main Release [84B]
已有 ftp://ftp.hk.debian.org stable/non-free Sources
下載:7 ftp://ftp.hk.debian.org stable/non-free Release [88B]
已有 ftp://ftp.hk.debian.org stable/contrib Sources
下載:8 ftp://ftp.hk.debian.org stable/contrib Release [87B]
已有 ftp://ftp.hk.debian.org stable/non-US/main Sources
已有 ftp://ftp.hk.debian.org stable/non-US/main Release
已有 ftp://ftp.hk.debian.org stable/non-US/non-free Sources
已有 ftp://ftp.hk.debian.org stable/non-US/non-free Release
已有 ftp://ftp.hk.debian.org stable/non-US/contrib Sources
已有 ftp://ftp.hk.debian.org stable/non-US/contrib Release
讀取 4992kB 用了 31s (159kB/s)
讀取套件清單中... 完成

搜尋套件 (apt-cache search)

Debian/Ubuntu/Xandros 等的官方軟件庫一般都有萬多個套件。如果加上一些非官方的軟件庫,套件的數量可能達數萬。要在這龐大的軟件庫找出想要安裝的套件就需要使用 “apt-cache search 關鍵字 ...” 搜尋套件名稱或描述包含 “關鍵字” 的套件,例如要搜尋和 “image manipulate” 相關的套件:

$ apt-cache search image manipulate
cinepaint - motion picture image painting and retouching tool
fujiplay - Interface for Fuji digital cameras
gnubik - 3D Rubik's cube game
gtkmorph - Digital image warp and morph (gtk)
gtkmorph-example - digital image warp and morph, examples
imagemagick - Image manipulation programs
jhead - manipulate the non-image part of Exif compliant JPEG files
jpegpixi - Remove hot spots from JPEG images with minimal quality loss
libgrass - GRASS GIS development libraries
libgrass-dev - GRASS GIS library development files
minc-tools - MNI medical image format tools
pdl - perl data language: Perl extensions for numerics
pike7.4-gdbm - Gdbm module for Pike
pike7.4-mysql - Mysql module for Pike
pike7.4-pg - Postgres module for Pike
tcllib - The Standard Tcl Library
xfig-libs - XFig image libraries and examples
xmorph - digital image warp and morph (x11)

如果只想搜尋名稱包含 “關鍵字” 的套件,可以加上選項 --names-only (短選項 -n):

$ apt-cache -n search imagemagick
imagemagick - image manipulation programs
graphicsmagick-imagemagick-compat - image processing tools providing ImageMagick interface

顯示套件資訊 (apt-cache show)

如果想知道個別套件詳細資訊,可以打 “apt-cache show 套件名稱”:

$ apt-cache show imagemagick
Package: imagemagick
Priority: optional
Section: graphics
Installed-Size: 5200
Maintainer: Ryuichi Arafune <arafune at debian.org>
Architecture: i386
Version: 6:6.0.6.2-2.4
Replaces: imagemagick-doc, geomview (<= 1.8.0)
Depends: libmagick6 (= 6:6.0.6.2-2.4)
Suggests: gs, html2ps, lpr
Conflicts: imagemagick-doc
Filename: pool/main/i/imagemagick/imagemagick_6.0.6.2-2.4_i386.deb
Size: 1465598
MD5sum: 4b9eb6cda5f5fe0c20040c9647ee2b6f
Description: Image manipulation programs
 Imagemagick is a set of programs to manipulate various image formats
 (JPEG, TIFF, PhotoCD, PBM, XPM, etc...). All manipulations can
 be achieved through shell commands as well as through a X11 graphical
 interface (display).
 .
 Possible effects: colormap manipulation, channel operations, thumbnail
 creation, image annotation, limited drawing, image distortion, etc...
 .
 This package suggests a postscript interpreter (gs) to read postscript
 files. It will however function happily without it (as long as you don't
 want to read postscript).

安裝套件 (apt-get install)

在 APT 系統安裝軟件很簡單,只需要在系統管理員 (即使用者 root) 輸入 “apt-get install 套件名稱” 命令,APT 系統就會自動幫您找出最新版本的位置和使用該套件所有所需的套件,並一拼幫您下載和安裝,免卻了很多麻煩。例如:

# apt-get install imagemagick
Reading Package Lists... Done
Building Dependency Tree... Done
Suggested packages:
  html2ps lpr
The following NEW packages will be installed:
  imagemagick
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/1466kB of archives.
After unpacking 5325kB of additional disk space will be used.
Selecting previously deselected package imagemagick.
(Reading database ... 60636 files and directories currently installed.)
Unpacking imagemagick (from .../imagemagick_6%3a6.0.6.2-2.4_i386.deb) ...
Setting up imagemagick (6.0.6.2-2.4) ...

移除套件 (apt-get remove)

要移除已安裝軟件亦很簡單,只需要在系統管理員 (即使用者 root) 輸入 “apt-get remove 套件名稱” 命令,APT 系統就會自動找出需要該套件才可以運作的套件,詢問您是否要一併套件。例如:

# apt-get remove imagemagick
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be REMOVED:
  imagemagick*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0B of archives.
After unpacking 5325kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 60867 files and directories currently installed.)
Removing imagemagick ...

很多套件都有一些配置檔案,而移除套件時一般不會移除配置檔案。一方面配置檔案的大小一般不會太大,另一方面檔再重新安裝該套件時仍可以使用舊配置。不過如果您想把配置檔案一併移除,可以加上選項 --purge,例如:

# apt-get --purge remove imagemagick
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be REMOVED:
  imagemagick*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0B of archives.
After unpacking 5325kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 60867 files and directories currently installed.)
Removing imagemagick ...
Purging configuration files for imagemagick ...

更新套件

更新所有套件 (apt-get upgrade)

在 APT 系統更新套件很簡單,只需要在系統管理員 (即使用者 root) 輸入 “apt-get upgrade” 命令,APT 系統就會自動找出有新版本的套件,並一拼幫您下載和安裝。但要留意過久沒有執行 “apt-get update” 命令可能會令電腦中各軟件庫的套件資料快取過時,所以最好進行更新前更新套件資料。例如:

# apt-get update
# apt-get upgrade

更新個別套件

如果只想更個別套件,同樣可以使用 “apt-get install 套件名稱” 命令,APT 系統就會自動幫您找出最新版本的位置和使用該套件新版本時需要一併更新的套件,並一拼幫您下載和安裝,免卻了很多麻煩。

相關頁面

相關連結

Personal tools