51

Possible Duplicate:
apt-get does not work with proxy

I have tried changing my proxy settings in a terminal as:

export HTTP_PROXY=http://10.1.3.1:8080

and

export http_proxy=http://10.1.3.1:8080

but when I try to install a new package or update apt-get, apt-get starts displaying messages from which it seems it is trying to connect to a previously set proxy:

sudo apt-get update  
0% [Connecting to 10.1.2.2 (10.1.2.2)] [Connecting to 10.1.2.2 (10.1.2.2)

I have tried setting the proxy via bashrc file but that din work either. As far as I remember 10.1.2.2 was set using GNOME GUI but I don't have access to the GUI right now so I am trying to set it from terminal.

Duncan Jones
  • 145
  • 9
Uthman
  • 1,528

3 Answers3

70

Okay just solved it. Adding following line to /etc/apt/apt.conf has solved the problem: Acquire::http::proxy "http://10.1.3.1:8080/";

If file does not exist, create it. Do not confuse it with apt.conf.d directory.

Uthman
  • 1,528
  • 8
    Great. The reason your manual export failed to affect apt-get is because sudo ignores that environment variable by default (i.e. it doesn't pass it on to the command). For one-off runs, you could do sudo env http_proxy=http://10.1.3.1:8080 apt-get update. Otherwise, you could configure sudo to allow http_proxy to fall through. – geirha Jul 02 '12 at 10:08
  • also if proxy using authentication then provide the details as sudo env http_proxy=http://<userid>:<password>@10.1.3.1:8080 apt-get update – sahasrara62 Mar 13 '20 at 05:31
63

The file:

/etc/environment

Is the correct place to specify system-wide environment variables that should be available to all processes. See https://help.ubuntu.com/community/EnvironmentVariables for details. Note that this is not a script file but a configuration file.

If you want this for the specified command only, use (as root):

http_proxy=http://10.1.3.1:8080 apt-get update
13

Edit your:

gedit /etc/profile

Enter the details in this format.

export http_proxy=http://username:password@proxyhost:port/ 
export ftp_proxy=http://username:password@proxyhost:port/

Then run the

sudo apt-get update

That should do it for you.

As stated above you can enter the proxy into apt.conf (Piyush Credit)

muru
  • 197,895
  • 55
  • 485
  • 740
LinuxBill
  • 2,067
  • I have mentioned in my question that I tried setting the proxy via bashrc file and then tried source /etc/bash.bashrc but apt-get is still trying to access the old repository. – Uthman Jul 02 '12 at 09:45
  • 3
    Besides that, /etc/bash.bashrc is the wrong place to set environment variables as it will only affect bash run interactively. Environment variables should be set in /etc/environment or /etc/profile. – geirha Jul 02 '12 at 10:05