如何為 apt-get 建立別名?

如何為 apt-get 建立別名?

我記得在一個 Debian 系統上,我曾經apt install package安裝過一個軟體包。之後會要求輸入密碼,比 更方便sudo apt-get install

現在我不確定我是如何設法使用第一個命令的。你能幫我嗎?

答案1

您也許可以為此建立一個別名。

假設您使用的是 Bash,請.bash_aliases在您的主目錄中建立一個檔案(如果該檔案尚不存在)。

然後,將以下行新增至文件:

alias apt='sudo apt-get'

現在關閉外殼並再次重新打開它。

現在您可以使用語法安裝任何新套件apt install <package-name>。請注意,自動完成功能不適用於別名。

答案2

apt為最新的基於 Debian 的發行版創建別名可能不是一個好主意apt-get。從 Debian Jessie (2015) 和 Ubuntu 15.10 (2015) 開始,存在以下apt命令

http://www.debian.org/doc/manuals/debian-faq/ch-pkgtools.en.html#s-apt-get http://manpages.ubuntu.com/manpages/wily/en/man8/apt.8.html

它實際上可以用來代替 apt-getandapt-cache

  apt-get update             ->  apt update
  apt-get upgrade            ->  apt upgrade
  apt-get dist-upgrade       ->  apt full-upgrade
  apt-get install package    ->  apt install package
  apt-get remove package     ->  apt remove package
  apt-get autoremove         ->  apt autoremove
  apt-cache search string    ->  apt search string
  apt-cache policy package   ->  apt list -a package
  apt-cache show package     ->  apt show package
  apt-cache showpkg package  ->  apt show -a package

它還包括新命令,full-upgrade例如apt-get.

答案3

開啟您的 bash_profile 或 bashrc。 (可能在 ~/.bashrc 或 ~/.bash_profile 中)。現在新增該行alias apt='sudo apt-get'。現在儲存文件,退出終端,然後重新打開它。

答案4

“使用最新的基於 Debian 的發行版創建 apt-get 別名可能不是一個好主意。從 Debbian Jessie (2015) 和 Ubuntu 15.10 (2015) 開始,就存在 apt 命令”

完全同意,我碰巧為 2 個更頻繁的 apt-get 命令創建了別名(更新升級) 作為:

別名 aptgupd='sudo apt-get update' 別名 aptgupg='sudo apt-get update'

只是一些其他路線的範例,希望對您有所幫助。

相關內容