Set Proxy for APT on Ubuntu/Debian / Linux / Debian / Set Proxy for APT on Ubuntu/Debian

Proxy servers (such as the Squid proxy) are often used in corporate networks to provide access to the Internet for internal devices. In order for your internal Ubuntu/Debian hosts to be able to install and update deb packages from external repositories, you need to configure the proxy settings for the APT (Advanced Packaging Tool) package manager. This article describes how to configure proxy connection settings for APT.

You can specify global proxy settings for APT in the /etc/apt/apt.conf file.

$ sudo touch /etc/apt/apt.conf
$ sudo mcedit /etc/apt/apt.conf

Add the following configuration lines here:

Acquire::http::proxy "";
Acquire::https::proxy "";
Acquire::ftp::proxy "";
Acquire::::Proxy "true";

use proxy for apt on ubuntu and debian

  • – your proxy server IP or DNS name
  • 3128 – proxy server port

You can set a username and password if authentication is required to connect to a proxy server:

Acquire::http::Proxy "http://user1:password@";
Acquire::https::Proxy "http://user1:password@";
Acquire::ftp::Proxy "ftp://user1:password@";

The next time you use apt or apt-update, a proxy server will be used to connect to the repositories.

If you have deployed your own local deb repositories, you can set apt to access them directly, rather than through a proxy. Add the following exclusion list to your apt.conf file:

Acquire::http::Proxy { DIRECT; DIRECT;

To check whether a proxy connection was used to install or update an Ubuntu package using apt, run the command:

$ cat /var/log/apt/history.log

The automatic keyword indicates that a proxy server was used to download these packages.


The above proxy settings for APT are global and apply to all users. You can use environment variables if you only want to use the APT proxy for the current user.

To do this, add the following lines to the end of the user’s ~/.profile:

export https_proxy=http://User:Password@
export http_proxy=http://User:Password@
export ftp_proxy=http://User:Password@

If you have specified a proxy server that is not available, you will see the following apt errors:

W: Failed to fetch Could not connect to ( - connect (111: Connection refused)
W: Some index files failed to download. They have been ignored, or old ones used instead.

If the credentials (username and password) used to connect to the proxy server are not correct, an error message will be displayed:

407 Proxy Authentication Required

Leave a Reply

Your email address will not be published. Required fields are marked *