How to set the proxy for APT on Ubuntu

This post is regarding: How to set the proxy for APT on Ubuntu 18.04, as I have set up that version of Ubuntu in my test machine. You can see if that works for other versions also.

APT a.k.a Aptitude will not use the HTTP Proxy environment variables. Instead, it has its own configuration file where you can set your proxy. This tutorial will show you how to set the proxy so that you may be able to install and update packages from remote repos.

If you filled in your proxy information during installation, the Apt configuration file would have been automatically updated. However, if you did not, then you must follow the following instructions.

Creating an Apt Proxy Conf File

Apt loads all configuration files under /etc/apt/apt.conf.d. We can create a configuration specifically for our proxy there, keeping it separate from all other configurations.

1. Create a new configuration file named proxy.conf.

sudo touch /etc/apt/apt.conf.d/proxy.conf

2. Open the proxy.conf file in a text editor.

sudo vi /etc/apt/apt.conf.d/proxy.conf

3. Add the following line to set your HTTP proxy.

Acquire::http::Proxy "http://user:password@proxy.server:port/";

4. Add the following line to set your HTTPS proxy.

Acquire::https::Proxy "http://user:password@proxy.server:port/";

5. Save your changes and exit the text editor.

I hope your proxy settings will be applied the next time you run Apt or login again or in a new Shell.

Simplifying the Configuration

There is an alternative way for defining the proxy settings. While similar, it removes some redundancy.

Just like in the first example, create a new file under the /etc/apt/apt.conf.d directory, and then add the following lines.

Acquire { HTTP::proxy "http://127.0.0.1:8080"; HTTPS::proxy "http://127.0.0.1:8080"; }

NOTE: Please remove the file or comment the non required lines in the file, when you more need to apply the proxy settings. 

This happens with me, where for some reason I had to apply proxy setting for APT in office. But since that was my virtual machine so I had not used it for few days. One day I required to do something at home. I was trying installing software but it was failing with not reachable errors and showing an IP address. For sometime I was not able to resolve the problem. Then suddenly it struck my mind that the IP is of proxy server. Then I commented the line in proxy.conf and all works well. 😅

Comments

Back To Top

Popular posts from this blog

error 18 at 0 depth lookup: self signed certificate

How to check fragmentation in MySQL tables

How to Drop or Remove or Decommission a Database in Oracle