Sunday, November 11, 2012

Setting up Proxy Settings for apt-get and wget in Ubuntu

To check if you have proxy configured in your system:
env | grep proxy

To setup proxy, add the following lines to these environment settings:

1) apt.conf (for apt-get)

sudo gedit /etc/apt/apt.conf

Acquire::http::Proxy "http://username:password@proxy:port";
Acquire::https::Proxy "http://username:password@proxy:port";
Acquire::ftp::Proxy "http://username:password@proxy:port";

2) wgetrc (for wget)

sudo gedit /etc/wgetrc

https_proxy  = http://username:password@proxy:port
http_proxy = http://username:password@proxy:port
ftp_proxy = http://username:password@proxy:port

Uncomment 'use_proxy = on'

Then reboot. sudo reboot


After rebooting your machine, you can now use apt-get and wget normally like sudo apt-get install package-name and wget url

If you don't want to change any configurations and just wanted to use proxy for the entire duration of your session:

For apt-get:
sudo http_proxy='http://username:password@proxy:port' apt-get install package-name

For wget:
export http_proxy='http://username:password@proxy:port' && wget url

OR

export http_proxy=http://proxy:port && wget --proxy-user=user --proxy-password=password url

Things to remember: 
1) Use this format if your proxy doesn't require login credentials: http://proxy:port
2) If your proxy server is Windows-based just like ours, don't forget to add your domain in your login.
ex. http://domain\username:password@proxy:port
3) Character escape your password if it has special characters.
ex. proxy-password=me\@123
4) If after setting up the http_proxy environment variable for wget and the connection still fails, also set up the https_proxy and ftp_proxy variables.

1 comment: