Configure proxy for APT?

To use a proxy, you need a proxy server. The IP and port have to be from this proxy server. Login and pwd must be your user and password on the proxy server (if the proxy requires login).

From help.ubuntu.com site:

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.

On some installations there will be no apt-conf file set up. Edit apt-conf file (or create a new one if you have no one yet) using the editor of your choice.

sudo nano /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.

If your proxy needs a login/password, substitute:

"http://yourproxyaddress:proxyport";

with:

"http://username:password@yourproxyaddress:proxyport";

using username and password from the proxy server.


This is a more general answer along with apt config.

As there a lot of places to configure proxy settings, it might get confusing at beginning. Let me summarize some things and suggest some good practices.

For console programs

Ex: wget, git and almost every console application which connects to internet.

If you want to configure proxy every time you run your commands for some reason then set the environment variables using following commands.

export http_proxy=http://DOMAIN\USERNAME:PASSWORD@SERVER:PORT/
export ftp_proxy=http://DOMAIN\USERNAME:PASSWORD@SERVER:PORT/

Else if you want to use the same settings everytime for all users, then use of these.

Configure in bashrc

$ nano /etc/bash.bashrc
export http_proxy=http://DOMAIN\USERNAME:PASSWORD@SERVER:PORT/
export ftp_proxy=http://DOMAIN\USERNAME:PASSWORD@SERVER:PORT/

Configure in /etc/environment

$ nano /etc/environment
https_proxy="http://myproxy.server.com:8080/" 
ftp_proxy="http://myproxy.server.com:8080/" ...

Configure using GUI

Open the network settings and set the your system wide network proxy.

Network -> Network proxy -> Configure -> Apply system wide.

But this might not be useful if you have authentication for the proxy.

For apt.

You need to do some extra work for apt, as incidentally apt doesn't obey environment variables,

$ nano /etc/apt/apt.conf
Acquire::http::Proxy "http://USERNAME:PASSWORD@SERVER:PORT";
Acquire::https::Proxy "https://USERNAME:PASSWORD@SERVER:PORT";

For everything out of this scope, there must be an option to configure proxy settings in the application itself. If not I'm sorry ;)


Something like the following should work:

Acquire::http::proxy "http://lgn:[email protected]:8080/";
Acquire::https::proxy "http://lgn:[email protected]:8080/";

Tags:

Apt