APT
常用指令
dpkg
# 列出已安裝的套件
dpkg -l
# 列出指定套件的檔案列表
dpkg -L <package name>
# 查詢系統內某個指令檔的套件名稱
dpkg -S <path to command>
# 查訊套件詳細資訊
dpkg -s <package name>
apt-get
# 更新套件庫資訊
apt-get update
# 安裝套件
apt-get install <package-name>
apt-get build-dep <package-name> ;安裝這個程式所需的相依性套件
apt-get -s install <package-name> ; 模擬安裝
# 移除套件及相關不需要的相依性套件
apt-get autoremove <package-name>
# 移除單個套件
apt-get purge <package-name>
# 安裝本機套件
apt-get update
dpkg -i <package-name>.deb
NOTE: 如果出現缺少套件的資訊,再執行
apt-get -f install
# 檢視套件的 Changelog
apt-get changelog <package-name>
apt-cache
apt-cache search <package-name>
apt-cache show <package-name>
apt-cache showpkg <package-name>
# 顯示套件的相依性
apt-cache depends <package-name>
其他指令
# 列出 GPG Key
apt-key list
# 避免套件被更新/升級
apt-mark hold glusterfs*
設定 proxy 方式連接
方法一:
export http_proxy=http://username:password@proxy.server.net:port/
; 若是 Windows AD 帳號, 加上反斜線兩次
export http_proxy=http://addomain\\username:password@proxy.server.net:port/
方法二:編輯 /etc/apt/apt.conf,加上這幾行。
Acquire::http::proxy "http://192.168.1.1:3128/";
Acquire::https::proxy "https://192.168.1.1:3128/";
Acquire::ftp::proxy "ftp://192.168.1.1:3128/";
Acquire::socks::proxy "socks://192.168.1.1:3128/";
新增台灣鏡像主機
# Debian
deb http://ftp.isu.edu.tw/pub/Linux/Debian/debian/ lenny main contrib non-free
deb-src http://ftp.isu.edu.tw/pub/Linux/Debian/debian/ lenny main contrib non-free
# Ubuntu
deb http://tw.archive.ubuntu.com/ubuntu/ saucy main restricted
deb-src http://tw.archive.ubuntu.com/ubuntu/ saucy main restricted
如果 Repository 主機已經移除該版本,可以指向到這位址:old-releases.ubuntu.com
deb http://old-releases.ubuntu.com/ubuntu/ karmic main restricted
套件降級版本
# Search for the older version of the Firefox
apt-cache showpkg firefox
# Downgrade to the specified version
apt-get install firefox=59.0.2+build1-0ubuntu1
FAQ
Q: GPG error: http://apt.insynchq.com rosa InRelease: The following signatures were invalid: KEYEXPIRED 1473479811
Solution:
$> apt-key list | grep expired
pub 2048R/ACCAF35C 2012-09-10 [expired: 2016-09-10]
$> sudo apt-key adv --recv-keys --keyserver keys.gnupg.net ACCAF35C
# 移除 GPG Key
$> sudo apt-key del ACCAF35C
Q: GPG error: http://repository.spotify.com testing InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY A87FF9DF48BF1C90
Solution:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A87FF9DF48BF1C90
Q: The Key of OpenSUSE is expired
GPG error: http://download.opensuse.org/repositories/graphics:/darktable:/stable/xUbuntu_18.04 InRelease: 以下簽名無效: EXPKEYSIG 040524A84C70D8B5 graphics:darktable OBS Project <graphics:darktable@build.opensuse.org>
W: 無法取得 http://download.opensuse.org/repositories/graphics:/darktable:/stable/xUbuntu_18.04/InRelease,以下簽名無效: EXPKEYSIG 040524A84C70D8B5 graphics:darktable OBS Project <graphics:darktable@build.opensuse.org>
Solution:
$> apt-key list | grep -A 1 expired
$> apt-key list | grep -A 1 過期
Warning: apt-key output should not be parsed (stdout is not a terminal)
pub rsa4096 2018-01-05 [SC] [過期: 2020-01-25]
68AE AE71 F9FA 1587 03C1 CBBC 8D04 CE49 EFB2 0B23
uid [ 已過期 ] Vivaldi Package Composer KEY04 <packager@vivaldi.com>
--
pub rsa2048 2017-12-26 [SC] [過期: 2020-03-05]
3247 B751 9EDB EAB4 22E9 00A3 0405 24A8 4C70 D8B5
uid [ 已過期 ] graphics:darktable OBS Project <graphics:darktable@build.opensuse.org>
$> sudo apt-key del 4C70D8B5 #specify last 8 characters
$> wget -nv http://download.opensuse.org/repositories/graphics:/darktable:/stable/xUbuntu_18.04/Release.key -O Release.key
$> apt-key --keyring Release.key finger
$> sudo apt-key add - < Release.key