Ubuntu 16.04 apt-get无法通过代理工作

时间:2016-07-26 13:36:01

标签: proxy apt-get ubuntu-16.04

在Ubuntu 14.04中,为了通过公司代理使用终端中的一些命令(如apt-get),我需要进行以下更改,超出系统设置>网络>网络代理> "应用系统范围" (羞辱你,Ubuntu)

/etc/environment (actually this is the only file modified by System Settings)
http_proxy="http://[webproxy]:[port]/"
https_proxy="https://[webproxy]:[port]/"
ftp_proxy="ftp://[webproxy]:[port]/"
socks_proxy="socks://[webproxy]:[port]/"

/etc/profile
export http_proxy=http://[username]:[password]@[webproxy]:[port]
export https_proxy=http://[username]:[password]@[webproxy]:[port]
export ftp_proxy=http://[username]:[password]@[webproxy]:[port]

sudo visudo
Defaults        env_reset
Defaults        env_keep = "http_proxy https_proxy ftp_proxy DISPLAY XAUTHORITY"

/etc/apt/apt.conf
Acquire::http::proxy "http://[username]:[password]@[webproxy]:[port]/";
Acquire::https::proxy "https://[username]:[password]@[webproxy]:[port]/";
Acquire::ftp::proxy "ftp://[username]:[password]@[webproxy]:[port]/";
Acquire::socks::proxy "socks://[username]:[password]@[webproxy]:[port]/";

or the same changes in
/etc/apt/apt.conf.d/95proxies

我认为至少以下命令(来自here

sudo http_proxy='http://[username]:[password]@[webproxy]:[port]' apt-get update

应该有用吗,对吧?

这就是我现在所记得的。甚至不确定是否所有这些都是必要的。不过,我在Ubuntu 16.04中做了所有这些更改,但仍然无法通过相同的代理(同一房间中的另一台计算机)使sudo apt-get update工作。得到了

Temporary failure resolving '[webproxy]'

我错过了什么?

3 个答案:

答案 0 :(得分:11)

创建新的空conf文件:$ sudo vi /etc/apt/apt.conf

如果您使用的是http代理,请将此行添加到文件中,否则使用https:ftp:
Acquire::http::Proxy "http://user:pass@proxy_host:port";

如果您没有代理的用户名和密码,请写下:
Acquire::http::Proxy "http://proxy_host:port";
注意:不要错过行尾的分号。

答案 1 :(得分:1)

我有同样的问题,我按照此解决方案修复它: 来自M.el Khamlichi的https://www.unixmen.com/45713-2/

  1. 在/ etc / apt /

    中创建一个apt.conf文件
    sudo vi /etc/apt/apt.conf
    
  2. 添加代理

    export http_proxy=http://192.168.168.180:3128 
    

    在这里你会记下你的数字。

  3. 将其添加到〜/ .bash.rc以使此命令永久化

    vi ~/.bash.rc
    

答案 2 :(得分:0)

在Ubuntu桌面上唯一对我有用的是

  1. 转到系统设置
  2. 搜索“代理”
  3. 转到网络设置
  4. 转到网络代理
  5. 输入HTTP代理和HTTP代理设置