
如何設定 apt-get 在代理後面工作?
答案1
http_proxy="http://host:port" apt-get something
應該管用。
如果您需要身份驗證,請嘗試
http_proxy="http://user:pass@host:port" apt-get something
如果您希望這是永久的,您可能應該在您的檔案中設定 http_proxy (和 ftp_proxy?) 變量,~/.bashrc
以便所有具有代理功能的應用程式將來都可以工作,例如“wget”。
答案2
在 /etc/apt/apt.conf 中,新增以下行:
Acquire::http::Proxy "http://MYDOMAIN\MYNAME:[email protected]:MYPORT"
答案3
代理是透過在本地(例如在 中)或全域(例如在 中)設定 和http_proxy
環境變數來指定的。幾乎所有網路軟體套件(如 apt-get、wget、curl 等)都遵循這些設定:ftp_proxy
all_proxy
~/.bashrc
/etc/bash.bashrc
# HTTP proxy without authentification
export http_proxy="http://host:port"
# HTTP proxy with authentification
export http_proxy="http://user:pass@host:port"
然而,以這種方式設置它們在運行時沒有幫助sudo apt-get ...
- 這是由於以下行/etc/sudoers
:
Defaults env_reset
這條線重置sudo
出於安全原因,使用時的所有環境變數。為了保持http_proxy
在呼叫中等的值sudo
,您可以指定env_reset
via的例外env_keep
:
# Exception specific to the command apt-get
Defaults!/usr/bin/apt-get env_keep="http_proxy https_proxy ftp_proxy"
# Exception specific to the user joe
Defaults:joe env_keep="http_proxy https_proxy ftp_proxy"
這樣,您就可以apt-get
兌現全球的apt-get
設定 http_proxy,而不是在某些神秘的 apt 特定設定檔中重複設定。