apt-get
-
更新:#apt-get update
更新 /etc/apt/sources.list 套件清單內容.root@ubuntu:~# apt-get update Ign http://us.archive.ubuntu.com trusty InRelease Hit http://security.ubuntu.com trusty-security Release.gpg Reading package lists... Done
通常檢查套件更新時,系統會先檢查套件有沒有什麼變化,如果沒有找到更新的東西會回傳 hit 或是 ign (ignore) .
Hit : 意味著 apt 檢查套件列表的時間戳 (timestamps) ,並沒有任何的變化.
Ign : 意味著是 PDIFF 索引文件中沒有改變,PDIFF 是為了加快更新速度,不用每次都下載完整的套件.
如果是有新的更新可以使用時會出現.
Get : 有檔案的更新版本可以安裝. -
升級:#apt-get upgrade
(同 #apt upgrade) 系統會依據 /etc/apt/sources.list 內容 (需要透過 #apt-get update 來更新清單內容) ,但不執行套件移除 或是 更新沒有安裝過的套件.如果會影響到其它套件的相依性該套件也不會更新.root@ubuntu:~# apt-get upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages were automatically installed and are no longer required: account-plugin-windows-live libupstart1 linux-headers-3.16.0-30 linux-headers-3.16.0-30-generic linux-image-3.16.0-30-generic linux-image-extra-3.16.0-30-generic Use 'apt-get autoremove' to remove them. The following packages will be upgraded: gir1.2-gtk-3.0 libgail-3-0 libgtk-3-0 libgtk-3-bin libgtk-3-common 5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 2,302 kB of archives. After this operation, 4,096 B of additional disk space will be used. Do you want to continue? [Y/n]
剛剛的 #apt-get update 主要是更新列表的內容,但真正要更新的指令是這個 #apt-get upgrade.
-
升級:#apt-get dist-upgrade
系統會依據 /etc/apt/sources.list 內容是更新套件 (需要透過 #apt-get update 來更新清單內容) ,與 upgrade 不同的是 他會處理套件相依性的問題,系統如果有重要更新套件 (未安裝過的) 也會一併安裝,也有可能會移除一些套件.root@ubuntu:~# apt-get dist-upgrade Reading package lists... Done Building dependency tree Reading state information... Done Calculating upgrade... Done The following packages were automatically installed and are no longer required: account-plugin-windows-live libupstart1 linux-headers-3.16.0-30 linux-headers-3.16.0-30-generic linux-image-3.16.0-30-generic linux-image-extra-3.16.0-30-generic Use 'apt-get autoremove' to remove them. The following packages will be upgraded: gir1.2-gtk-3.0 libgail-3-0 libgtk-3-0 libgtk-3-bin libgtk-3-common 5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 2,302 kB of archives. After this operation, 4,096 B of additional disk space will be used. Do you want to continue? [Y/n] n
如果是要讓系統升級 (Ubuntu 14.04 到 16.04) 就需要 #do-release-upgrade https://benjr.tw/95594
-
安裝:#apt-get install
不用考慮到相依性的問題,系統會自行處理相依性問題.root@ubuntu:~# apt-get install ssh Reading package lists... Done Building dependency tree Reading state information... Done ssh is already the newest version. The following packages were automatically installed and are no longer required: account-plugin-windows-live libupstart1 linux-headers-3.16.0-30 linux-headers-3.16.0-30-generic linux-image-3.16.0-30-generic linux-image-extra-3.16.0-30-generic Use 'apt-get autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
目前我的 ssh 已經安裝過了,而且是最新的版本.
root@ubuntu:~# apt-get install sshd Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package sshd
沒有 sshd 這個套件,通常不是真的沒有要不然就是你忘記先更新套件列表 (#apt-get update)
-
移除:#apt-get remove
不用考慮到相依性的問題,系統會自行處理相依性問題.root@ubuntu:~# apt-get remove ssh Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: account-plugin-windows-live libupstart1 linux-headers-3.16.0-30 linux-headers-3.16.0-30-generic linux-image-3.16.0-30-generic linux-image-extra-3.16.0-30-generic Use 'apt-get autoremove' to remove them. The following packages will be REMOVED: ssh 0 upgraded, 0 newly installed, 1 to remove and 5 not upgraded. After this operation, 29.7 kB disk space will be freed. Do you want to continue? [Y/n]
-
移除:#apt-get purge
除了移除程式連設定檔會一併移除掉.root@ubuntu:~# apt-get purge ssh Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: account-plugin-windows-live libupstart1 linux-headers-3.16.0-30 linux-headers-3.16.0-30-generic linux-image-3.16.0-30-generic linux-image-extra-3.16.0-30-generic Use 'apt-get autoremove' to remove them. The following packages will be REMOVED: ssh* 0 upgraded, 0 newly installed, 1 to remove and 5 not upgraded. After this operation, 29.7 kB disk space will be freed. Do you want to continue? [Y/n]
剛剛 #apt-get remove 顯示移除套件名稱為 ssh, 但 #apt-get purge 顯示為 ssh* <- 表示關於 ssh 的除了套件還會一併將設定檔移除掉.
-
清除:#apt-get clean
清除位於 /var/cache/apt/archives 的下載暫存套件檔案.root@ubuntu:~# apt-get clean
apt-cache
- 搜尋:#apt-cache search
root@ubuntu:~# apt-cache search ssh backuppc - high-performance, enterprise-grade system for backing up PCs byobu - powerful, text based window manager and shell multiplexer bzr - easy to use distributed version control system bzr-doc - easy to use distributed version control system (documentation) cloud-init - Init scripts for cloud instances cvs - Concurrent Versions System ....
可以顯示套件資訊,類似 #rpm -qi 的方式
root@ubuntu:~# apt-cache show ssh Package: ssh Priority: optional Section: net Installed-Size: 29 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian OpenSSH Maintainers <debian-ssh@lists.debian.org> Architecture: all Source: openssh Version: 1:6.6p1-2ubuntu2.3 Depends: openssh-client (>= 1:6.6p1-2ubuntu2.3), openssh-server (>= 1:6.6p1-2ubuntu2.3) Filename: pool/main/o/openssh/ssh_6.6p1-2ubuntu2.3_all.deb Size: 1114 MD5sum: b04003e15994fb4283d7d258bbe12151 SHA1: 790f3fb535bad05f1570631c7def57a1c88501d9 SHA256: d96e8e7d66075d2f95a9ac31d2d7a14a06ccf645942f156811ea6135dd3b520f Description-en: secure shell client and server (metapackage) This metapackage is a convenient way to install both the OpenSSH client and the OpenSSH server. It provides nothing in and of itself, so you may remove it if nothing depends on it. Description-md5: b00e309365895c14a10af55945efb136 Homepage: http://www.openssh.org/ Bugs: https://bugs.launchpad.net/ubuntu/+filebug Origin: Ubuntu Supported: 5y .......
showpkg 跟 show 的作用有點像,在 man page 裡面可以看到這兩個的定義.
showpkg – Show some general information for a single package
show – Show a readable record for the package
其實都是顯示套件內容但顯示會不一樣.都可以試著讀讀看.
root@ubuntu:~# apt-cache showpkg ssh Package: ssh Versions: 1:6.6p1-2ubuntu2.3 (/var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_trusty-updates_main_binary-i386_Packages) (/var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_trusty-security_main_binary-i386_Packages) (/var/lib/dpkg/status) Description Language: File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_trusty_main_binary-i386_Packages MD5: b00e309365895c14a10af55945efb136 Description Language: en File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_trusty_main_i18n_Translation-en MD5: b00e309365895c14a10af55945efb136 1:6.6p1-2ubuntu1 (/var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_trusty_main_binary-i386_Packages) Description Language: File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_trusty_main_binary-i386_Packages MD5: b00e309365895c14a10af55945efb136 Description Language: en File: /var/lib/apt/lists/us.archive.ubuntu.com_ubuntu_dists_trusty_main_i18n_Translation-en MD5: b00e309365895c14a10af55945efb136 Reverse Depends: ssh-askpass-gnome,ssh 1:3.5p1-3 ssh-askpass-gnome,ssh 1:1.2pre7-4 openssh-server,ssh ....... Dependencies: 1:6.6p1-2ubuntu2.3 - openssh-client (2 1:6.6p1-2ubuntu2.3) openssh-server (2 1:6.6p1-2ubuntu2.3) 1:6.6p1-2ubuntu1 - openssh-client (2 1:6.6p1-2ubuntu1) openssh-server (2 1:6.6p1-2ubuntu1) Provides: 1:6.6p1-2ubuntu2.3 - 1:6.6p1-2ubuntu1 - Reverse Provides:
apt-file
前面的 apt-get , apt-cache 都沒有辦法查詢套件安裝了哪一些檔案,這時候可以透過 apt-file 來查詢,不過他非預設安裝,需要額外安裝.
root@ubuntu:~# apt-get install apt-file
安裝後的第一步就是先更新資料庫.
root@ubuntu:~# apt-file update
現在就可以來搜尋套件安裝了哪一些檔案,而這些套件存放的地方在哪裡,都會顯示出來.
root@ubuntu:~# apt-file list e2fsprogs e2fsprogs: /etc/mke2fs.conf e2fsprogs: /sbin/badblocks e2fsprogs: /sbin/debugfs e2fsprogs: /sbin/dumpe2fs e2fsprogs: /sbin/e2fsck ..............
未安裝的程式也可以查詢,如我要查 #/sbin/ifconfig 是在哪一個套件裡面.
root@ubuntu:~# apt-file find ifconfig |grep -i /sbin/ linux-cloud-tools-common: /usr/sbin/hv_set_ifconfig linux-lts-vivid-cloud-tools-common: /usr/sbin/hv_set_ifconfig net-tools: /sbin/ifconfig python-ethtool: /usr/sbin/pifconfig
如果你是要透過 Http-proxy 使用 apt 請參考 https://benjr.tw/91047
3 thoughts on “Linux 套件管理 – APT”