apt-get behind proxy on VirtualBox Ubuntu

8

3

how can I set apt-get to work behind proxy?

simone

Posted 2011-04-11T13:21:17.710

Reputation: 183

Answers

8

http_proxy="http://host:port" apt-get something

should work.

If you require authentication, try

http_proxy="http://user:pass@host:port" apt-get something

And if you want this to be permenant, you should probably set the http_proxy (and ftp_proxy?) variables in your ~/.bashrc so that all of your proxy-capable applications will work in the future, e.g. 'wget'.

Pricey

Posted 2011-04-11T13:21:17.710

Reputation: 4 262

2one more thing to note is that if the password contains '@' then replace it with '%40' (without quotes),else it will not work – dotslash – 2011-11-06T09:16:09.180

8

in /etc/apt/apt.conf, add the line:

Acquire::http::Proxy "http://MYDOMAIN\MYNAME:MYPASS@MY.PROXY.COM:MYPORT"

From: http://ubuntuforums.org/showthread.php?t=96802

(Note: completely stolen from this answer to my similar question on SF. Cred to Grizzly)

squillman

Posted 2011-04-11T13:21:17.710

Reputation: 5 676

My filename was different but this is what worked for me /etc/apt/apt.conf.d/01proxy – Jackie – 2015-12-30T15:57:25.440

The line needs to end with a ; – Verma – 2013-12-19T10:57:24.313

4

A proxy is specified by setting the http_proxy, ftp_proxy and all_proxy environment variables, either locally (e.g. in ~/.bashrc) or globally (e.g. in /etc/bash.bashrc). These settings are honored by virtually all net-software packages (like apt-get, wget, curl etc.):

# HTTP proxy without authentification
export http_proxy="http://host:port"
# HTTP proxy with authentification
export http_proxy="http://user:pass@host:port"

However, setting them this way does not help when running sudo apt-get ... - and that is due to this line in /etc/sudoers:

Defaults env_reset

This line resets all environment variables when using sudo, for security reasons. In order to keep the values of http_proxy etc. in a sudo invocation, you can specify exceptions to 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"

This way, you get apt-get to honor the global setting for http_proxy, instead of duplicating the setting for apt-get in some arcane apt-specific config file.

DevSolar

Posted 2011-04-11T13:21:17.710

Reputation: 3 860

This env_reset line is /etc/sudoers is really important! – Ari – 2014-09-08T19:19:45.773

1@Ari: Yes it is; that is why I showed how to disable it specifically for apt-get and specifically for the variables necessary, instead of saying "just remove the line". – DevSolar – 2014-09-09T07:32:26.057

@DevSolar: yes, and plus 1 for that! – Ari – 2014-09-09T17:18:09.090

This is the real answer in my opinion, because you will all the time use sudo apt-get ... for anything. So without this entry in /etc/sudoers, it will not work. – mliebelt – 2013-12-24T08:42:16.917