How to Use APT with Proxy on Ubuntu and Debian

How to Use APT with Proxy on Ubuntu and Debian

This guide will show you how to set a proxy for the APT package manager 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, you have unsuccessfully tried to install packages.

APT Failed behind Proxy

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

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 directory. Therefore, we can create a specific configuration for our proxy, 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 name 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 proxy server’s port.

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 of 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, 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, install packages, etc.

APT Working via Proxy

Leave a Reply

Your email address will not be published.