)aptitude

來源:互聯網
上載者:User
Apt 不止是 apt-get

ubuntu(debian)下使用 apt-get 或 synaptic(新立得) 安裝軟體是件很輕鬆的事情. 除了簡單的安裝軟體, apt工具集還有許多特別情況下的用法.

任何時候請記住 man 手冊是良師.

1. 使用 aptitude 代替 apt-get .
aptitude 雖然沒有 apt-get 的"超級牛力", 但功能卻比 apt-get 更強大
首先, 像 apt-get 一樣, 可以安裝軟體

代碼:
aptitude install pack-foo

aptitude 解決依賴關係比 apt-get 更智能. 有時用 apt-get 安裝軟體時會出現 "XXX 需要 XXXX, 但 XXX
已安裝" 這類的錯誤. 這通常是因為某些軟體包過新造成的. 此時使用 aptitude, aptitude 會發現問題並給出幾個解決方案,
我們只需接受符合心意的方案就可以了.

aptitude 的另外一個優點是會自動記錄那些包是"自動安裝"(即因依賴關係而安裝的), 如果依賴"自動安裝"包的包都沒被安裝, 該"自動安裝"包(此時已無用)就會自動刪除.
使用這兩個命令可以控制包的"自動安裝"屬性

代碼:
aptitude markauto pack-foo #標記成"自動安裝"
aptitude unmarkauto pack-foo #標記成"手動安裝"

刪除軟體時使用 markauto 代替 remove, 就可以避免誤刪重要的包了.
當然, 新版的新立得和 apt-get 也有相似功能, 但貌似不與 aptitude 使用同一個資料庫, 所以建議只使用 aptitude 管理軟體包.

aptitude 還提供了更靈活的控制軟體包版本的方式

代碼:
hold         - 將軟體包置於保持狀態
unhold       - 取消對一個軟體包的保持命令
forbid-version - 禁止 aptitude 升級到某一特定版本的軟體包。

以前幾周的 libcairo 事件作例子:

代碼:
sudo aptitude install libcairo2=1.4.10-1ubuntu4 # 強制降級
sudo aptitude forbid-version libcairo2=1.4.10-1ubuntu4.1 # 封掉出錯的版本
sudo aptitude markauto libcairo2 #恢複auto屬性

參看 man 手冊裡對 install 操作的描述, 有更多控制方法.

aptitude reinstall 重新安裝軟體包, 相當於 apt-get --reinstall install
aptitude purge 徹底刪除軟體包, 相當於 apt-get --purge remove
一個小技巧

代碼:
aptitude purge `dpkg -l|grep '^rc'|awk '{print $2}'`

aptitude 還集合了多個 apt 工具的功能

代碼:
search       - 按名稱 和/或 運算式搜尋軟體包
show       - 顯示一個軟體包的詳細資料
download     - 下載軟體包的 .deb 檔案

search 操作有點特別

代碼:
aptitude search "foo bar" # 關鍵詞 foo 和 bar 都要出現
aptitude search foo bar # 相當於"或"

不過 aptitude 有個小缺點, 預設會將"推薦"的包當成"依賴"的包處理. 這樣設定一下就可以解決問題
在自己和root的家目錄下的 .aptitude/config 檔案加一句

代碼:
aptitude::Recommends-Important "false";

更詳細的用法參看 man aptitude.
另外:
1.aptitude 的互動模式貌似很混亂, 不如用新立得.
2.慎用 aptitude install -f .

2. 獲得軟體包的
很簡單

使用新立得:
1.選中要安裝的包
2.檔案 -> 產生包下載指令碼

使用 apt-get

代碼:
apt-get --print-uris install pack-foo

3. 安裝齊編譯需要的包
首先確定你添加了 deb-src 源, 就像這種

代碼:
deb-src http://ubuntu.cn99.com/ubuntu/ gutsy main restricted universe multiverse

並已經 apt-get update
然後就可以

代碼:
apt-get build-dep pack-foo

把編譯 pack-foo 需要的包安裝好

PS: 更強悍的方法是用 apt-build, 不過這樣就把 ubuntu 搞的太像 gentoo 了. 有興趣的朋友可以自己看 apt-build 的 man.

4. 找某個檔案在哪個包裡
如果是安裝了的包, 可以用 dpkg -S, 但此法對未安裝的包就無效了.
此時可使用 apt-file

代碼:
$ apt-file help
apt-file version 2.0.8.2
(c) 2002 Sebastien J. Gross <sjg@debian.org>

apt-file [options] action [pattern]

Configuration options:
    --sources-list      -s  <file>      sources.list location
    --cache             -c  <dir>       Cache directory
    --architecture      -a  <arch>      Use specific architecture
    --cdrom-mount       -d  <cdrom>     Use specific cdrom mountpoint
    --package-only      -l              Only display packages name
    --fixed-string      -F              Do not expand pattern
    --ignore-case       -i              Ignore case distinctions
    --regexp            -x              pattern is a regular expression
    --verbose           -v              run in verbose mode
    --dummy             -y              run in dummy mode (no action)
    --help              -h              Show this help.
    --version           -V              Show version number

Action:
    update                      Fetch Contents files from apt-sources.
    search|find <pattern>       Search files in packages
    list|show   <pattern>       List files in packages
    purge                       Remove cache files

此工具在尋找編譯時間缺的檔案時很有用, 用前記得先 apt-file update

PS: auto-apt 有相同功能, 而且可以檢測進程需要哪些缺少的檔案, 自動提示使用者選擇安裝相應的包.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.