How to Use APT with Proxy on Ubuntu and Debian

Need to configure a proxy for APT? Here's how to do it.

Use APT with Proxy on Ubuntu and Debian

This guide will show you how to set proxy for APT package manger so that you may be able to install and update packages from remote repos.

Using a proxy server as an internet access intermediary is a common business scenario. If you are running Ubuntu or Debian system behind a proxy server, chances are you have unsuccessfully tried to install packages.

APT Failed behind Proxy

Configure APT to Work with a Proxy Server

It can be done easily. APT loads all configuration files under the /etc/apt/apt.conf.d direcory. Therefore, we can create a configuration specifically for our proxy there, keeping it separate from all other configurations.

1. Create New Empty File

You need to create a new empty file inside /etc/apt/apt.conf.d/ directory. Let’s named it proxy.conf. Of course the name can be anything you like.

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

2. Open the proxy.conf File in a Text Editor

Next open the proxy.conf file with your preferred text editor.

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

3. Add APT Proxy Configuration

You need to have the IP address and the port of the proxy server.

To set your HTTP proxy, add the following line:

Acquire::http::Proxy "http://proxy_server:port/";

To set your HTTPS proxy, add the following line:

Acquire::https::Proxy "http://proxy_server:port/";

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

Acquire {
  HTTP::proxy "http://proxy_server:port/";
  HTTPS::proxy "http://proxy_server:port/";

If your proxy supports authentication and requires a username/password for login, simply use:

Acquire::http::Proxy "http://user:[email protected]_server:port/";

Save your changes and exit the text editor.

Note: Keep in mind that proxy_server and port from the examples above should be replaced with the proper proxy IP address/name and port.

4. Test APT Proxy Configuration

Now APT will use the proxy settings to get updates and installing packages etc.

APT Working via Proxy

Leave a Reply

Your email address will not be published.

Latest from Linux Knowledge