How to run "sudo apt-get update" through proxy in commandline?

In some releases sudo is configured in such a way that all environment variables all cleared when running the command. To keep the value for your http_proxy and fix this, you need to edit /etc/sudoers, run:

visudo

Then find a line that states:

Defaults env_reset 

and add after it:

Defaults env_keep = "http_proxy ftp_proxy" 

Things will start working as expected.

Thanks to kdogksu in the Ubuntu Forums for finding the solution for this.

In order to not only fix apt-get but also graphical X11 utils as e.g synaptic,mintintall, ...) the following line in /etc/sudoers should do the job :

Defaults env_keep = "http_proxy https_proxy ftp_proxy DISPLAY XAUTHORITY"

Use this.

ubuntu@ubuntu:~$ cat /etc/apt/apt.conf
Acquire::http::Proxy "http://Username:[email protected]:8080";

This is what I use. Works perfectly.

Apt also allows individual settings to be placed in files under /etc/apt/apt.conf.d/, so this has exactly the same effect as the above, but may be easier to maintain if you have other lines in the .conf file:

ubuntu@ubuntu:~$ cat /etc/apt/apt.conf.d/05proxy
Acquire::http::Proxy "http://Username:[email protected]:8080";