Tech, Gadgets, Photography, Social Media and Poor Spelling

How to get APT to work through a proxy..

APT is the core of package management on Debian based systems, its a powerful suite of tools for getting and managing packages onto the system.

As powerful as the Apt suite is, it has problems as I found out this week working through a proxy server. Something i’ve recently implemented.

There are Three ways for doing this:

Temporary proxy session 

This is a temporary method that you can manually use each time you want to use apt-get through a http-proxy. This method is useful if you only want to temporarily use a http-proxy. 

Enter this line in the terminal prior to using apt-get (substitute your details for yourproxyaddress and proxyport). 

export http_proxy=http://yourproxyaddress:proxyport

APT configuration file method 

This method uses the apt.conf file which is found in your /etc/apt/ directory. This method is useful if you only want apt-get (and not other applications) to use a http-proxy permanently. 

IconsPage/info.png On some installations there will be no apt-conf file set up. This procedure will either edit an existing apt-conf file or create a new apt-conf file. 

gksudo gedit /etc/apt/apt.conf 

Add this line to your /etc/apt/apt.conf file (substitute your details for yourproxyaddress and proxyport). 

Acquire::http::Proxy "http://yourproxyaddress:proxyport"; 

Save the apt.conf file.

BASH rc method 

This method adds a two lines to your .bashrc file in your $HOME directory. This method is useful if you would like apt-get and other applications for instance wget, to use a http-proxy. 

gedit ~/.bashrc 

Add these lines to the bottom of your ~/.bashrc file (substitute your details for yourproxyaddress and proxyport) 

export http_proxy 

Save the file. Close your terminal window and then open another terminal window or source the ~/.bashrc file: 

source ~/.bashrc 

Test your proxy with sudo apt-get update and whatever networking tool you desire. You can use firestarter or conky to see active connections.

If you make a mistake and go back to edit the file again, you can close the terminal and reopen it or you can source~/.bashrc as shown above. 

source ~/.bashrc

If you don’t want to go through the proxy for certain addresses, use the no_proxy variable. This is a comma-separated list of domains which you do not want resolved via the proxy. Unfortunately wild cards are not supported (so you can’t just put 192.168.* 😦 ) and the maximum number of entries in this list is 16. Here is an example:

export no_proxy=",localdomain"

Of course, the proxy settings will be forgotten when you log out. To make the proxy setting a little more permanent, you can set your proxy variables in /etc/profile

Something I did notice with all of this however was if you use sudo with a command the sudo command may throw up a wobbly. To get round this..

Instead of setting sudo proxy using export command try this 

sudo visudo 

Then add the following line 

Defaults env_keep += “ftp_proxy http_proxy https_proxy” 

This will ensure that your normal users values will be inherited by sudo

As a final side note, the http_proxy works with wget too, and any command launched from the terminal including gui apps running from the command line.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


This entry was posted on November 26, 2011 by in regular and tagged , , , , , .
%d bloggers like this: