Answers:
http_proxy="http://host:port" apt-get something
应该管用。
如果您需要身份验证,请尝试
http_proxy="http://user:pass@host:port" apt-get something
而且,如果您希望此设置永久存在,则可能应该在您的变量中设置http_proxy(和ftp_proxy?)变量,~/.bashrc以便将来所有支持代理的应用程序都可以使用,例如“ wget”。
代理通过将指定的http_proxy,ftp_proxy和all_proxy环境变量,或者本地(例如,在~/.bashrc)或全局(例如,在/etc/bash.bashrc)。几乎所有网络软件程序包(例如apt-get,wget,curl等)都尊重这些设置:
# 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 etc. 的值保持在sudo调用中,您可以为env_resetvia 指定异常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可以遵守http_proxy 的全局设置,而不必apt-get在某些神秘的apt特定配置文件中复制该设置。
sudo apt-get ...任何东西。因此,如果没有此项/etc/sudoers,它将无法工作。
env_reset条线/etc/sudoers真的很重要!
apt-get和专门用于必要的变量,而不是说“只删除行”。