How to Use APT with Proxy on Ubuntu and Debian

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

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/";Code language: PHP (php)

To set your HTTPS proxy, add the following line:

Acquire::https::Proxy "http://proxy_server:port/";Code language: PHP (php)

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/";
}Code language: CSS (css)

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

Acquire::http::Proxy "http://user:password@proxy_server:port/";Code language: PHP (php)

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
Bobby Borisov

Bobby Borisov

Bobby, an editor-in-chief at Linuxiac, is a Linux professional with over 20 years of experience. With a strong focus on Linux and open-source software, he has worked as a Senior Linux System Administrator, Software Developer, and DevOps Engineer for small and large multinational companies.