Configure proxy for APT?

I need to configure proxy. There wasn't apt.conf file in etc/apt/ so I've created it using nano.

But I don't understand what I need to write there. I've written http_proxy = http://lgn:[email protected]:8080/ there and then restarted networking. But when I try to apt-get update - it doesn't work.

Actually I don't understand what port and ip I should write in apt.conf file(there was example with 192.168.1.254 ip and 8080 port so I decided to use them).


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 ;)