← Back to Blog

Configuring apt and apt-get via Proxy in Debian and Ubuntu: Acquire::http::Proxy and 9 Common Errors

A step-by-step guide to configuring a proxy for apt and apt-get in Debian and Ubuntu — three working methods, authentication, SOCKS5, and solutions to common errors when updating packages.

📅November 26, 2026

If a server running Debian or Ubuntu is behind a corporate proxy, in an isolated network without direct internet access, or if you need to update packages through an IP from another region — the command apt-get update simply hangs or fails with a connection error. We will explore all the working methods to configure a proxy for apt, set up authentication, and quickly identify why packages are not downloading.

Why configure a proxy for apt

The apt package manager (and its wrapper apt-get) accesses repositories via HTTP and HTTPS, and by default does so directly, through the server's interface. If the server is behind a firewall without NAT, is in a closed corporate network, or if you are managing dozens of virtual machines across different hosts and want all outgoing traffic to go through one controlled node — a proxy is essential.

Another story is testing infrastructure and CI/CD pipelines. When you need to build a Docker image or run package installations through an IP from a specific region (for example, to check if a mirror repository is accessible from another country, or to simulate client server behavior), a proxy for apt becomes a working tool for a DevOps engineer, rather than a luxury. In such tasks, datacenter proxies are often used — they provide stable speed and low latency, which is critical during mass apt-get updates on multiple machines.

It is important to understand: apt does not automatically read the system proxy settings from the browser or variables from /etc/environment in 100% of cases — behavior depends on the version and how the command is invoked (via sudo, in cron, in a Docker build). Therefore, below are three independent methods that everyone should know to avoid wasting hours on debugging.

Method 1: apt.conf.d file and Acquire::http::Proxy

The most reliable and permanent method is to create a separate config file in the /etc/apt/apt.conf.d/ directory. This path is preferred because the settings are not lost during system updates and work the same for apt, apt-get, and apt-cache.

sudo nano /etc/apt/apt.conf.d/95proxies

Inside the file, write the Acquire directives for HTTP and HTTPS separately — apt does not combine them automatically:

Acquire::http::Proxy "http://192.0.2.10:3128/";
Acquire::https::Proxy "http://192.0.2.10:3128/";

Pay attention to the quotes and the semicolon at the end of each line — this is mandatory syntax, and missing any character will lead to a config parsing error. If HTTPS repositories go through the same proxy as HTTP, the value can be duplicated, but the protocol in the URL always remains http://, even for the Acquire::https line — the proxy server itself "tunnels" the HTTPS traffic using the CONNECT method.

The numerical name of the file (95proxies) is not accidental: apt reads files from apt.conf.d in alphabetical/numerical order, and if you already have other configs, a high number ensures that the proxy setting is applied last and will not be overwritten. To disable the proxy, simply delete the file or comment out the lines with //.

Method 2: environment variables http_proxy and https_proxy

The second option is the classic environment variables, which are understood not only by apt but also by wget, curl, and git. This is suitable when the proxy is needed temporarily, within a single session or script, and you do not want to change system configs.

export http_proxy="http://192.0.2.10:3128/"
export https_proxy="http://192.0.2.10:3128/"
sudo -E apt-get update

The key nuance is the -E flag with sudo. Without it, sudo runs the command with a clean environment, and the proxy variables set in a regular user session are lost. Many beginners waste time on this error: the proxy is set, but apt-get still goes directly.

For permanent application at the system level, the variables are added to /etc/environment, but this method does not work reliably for all processes — systemd units, for example, read environment variables in their own way. Therefore, for server tasks and automation, we recommend method 1 (apt.conf.d), while environment variables are for one-off sessions and debugging.

Method 3: one-time configuration via apt-get -o

If the proxy is needed literally for one command — for example, to test the availability of a repository through another IP — it is not necessary to touch the configuration files. The -o option allows you to pass the Acquire directive directly in the command line:

sudo apt-get -o Acquire::http::Proxy="http://192.0.2.10:3128/" update

This method is convenient in CI/CD pipelines and Dockerfiles, where you do not want to leave permanent proxy settings inside the image. In a Dockerfile, it looks like this:

RUN apt-get -o Acquire::http::Proxy="http://192.0.2.10:3128/" \
    -o Acquire::https::Proxy="http://192.0.2.10:3128/" \
    update && apt-get install -y curl

The advantage of this method is clarity and the absence of side effects on subsequent build commands. The downside is that you have to duplicate the option in each RUN block if the proxy is needed in multiple steps.

Authentication with username and password

If the proxy requires authentication, the username and password are inserted directly into the URL before the host address. The syntax is the same for all three methods above:

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

A common problem here is special characters in the password. If the password contains @, :, or /, they need to be URL-encoded (for example, @ becomes %40), otherwise apt will incorrectly parse the string and return a connection error instead of an authentication error, which can be very confusing during diagnosis.

Storing the username and password directly in apt.conf.d is not always safe, especially if the file ends up in version control or a Docker image with public access. For production, it is better to move credentials to a separate file with 600 permissions and include it via #include or pass it as a build-arg in Docker with subsequent removal from the final layer of the image.

SOCKS5 proxy and apt: nuances

An important point that is often overlooked: apt and apt-get do not natively work with SOCKS5 proxies. The directive Acquire::http::Proxy only accepts HTTP proxies as a value. If you only have SOCKS5 (and residential and mobile proxies are most often issued in this format), you will have to use a layer — a local HTTP proxy that redirects traffic into a SOCKS5 tunnel.

The simplest option is the privoxy utility, which accepts HTTP requests and forwards them through SOCKS5:

sudo apt-get install privoxy
echo "forward-socks5 / 127.0.0.1:1080 ." | sudo tee -a /etc/privoxy/config
sudo systemctl restart privoxy

After that, in apt.conf.d, specify the local address of privoxy, usually http://127.0.0.1:8118/, and privoxy will automatically proxy the traffic further through the SOCKS5 tunnel on port 1080 (which can be set up via ssh -D or a ready SOCKS5 client). An alternative is the cntlm utility or proxychains for more flexible routing. However, if the task is stable package updates on the server, it is easier to take a proxy in HTTP(S) format directly: for server scenarios, this is more convenient than building layers.

Common errors and their solutions

Below is a table of the most common problems when configuring a proxy for apt and quick solutions to them.

Error Cause Solution
Could not resolve host Proxy is incorrectly set or not applied Check the syntax of apt.conf.d, quotes, and semicolon
407 Proxy Authentication Required Username/password not provided or incorrect URL format Add user:password@ before the host address, encode special characters
Connection timed out Proxy is unavailable, port is closed, or firewall is blocking outgoing traffic Check proxy availability via curl -x, open the required port on the firewall
Unable to connect to 127.0.0.1:8118 privoxy is not running or is listening on a different port systemctl status privoxy, check /etc/privoxy/config
sudo ignores environment variables sudo runs the command with a clean environment Use sudo -E or set the proxy in apt.conf.d
E: The method driver /usr/lib/apt/methods/https could not be found The apt-transport-https package is not installed sudo apt-get install apt-transport-https (relevant for older versions)
Certificate verification failed Proxy is doing MITM and replacing the TLS certificate Add the proxy's root certificate to ca-certificates or change the proxy
apt-get hangs without errors Proxy accepts SOCKS5, but apt sends an HTTP request Set up privoxy/cntlm as a layer between apt and SOCKS5
Settings are not applied in Docker build apt.conf.d is not copied to the image or is cleared in the next layer Pass the proxy via -o in each RUN or build-args

How to check if the proxy is working

Before figuring out why apt-get is not updating packages, it is worth ensuring that the proxy itself is working and responding. The quickest way is to check via curl directly, without apt:

curl -x http://user:[email protected]:3128/ -I https://deb.debian.org

If curl returns a code 200 or 301/302 — the proxy is alive, and the problem lies in the apt configuration. If curl also does not respond — the issue is with the proxy server itself, not the package manager settings.

For detailed diagnostics of apt itself, enable verbose logging via the Debug::Acquire::http flag — it will show which proxy address is being used, what headers are sent, and at which stage the connection is dropped:

sudo apt-get -o Debug::Acquire::http=true update 2>&1 | head -50

This output usually immediately shows whether the proxy was picked up at all — if there are no lines with the proxy address in the log, it means the configuration did not apply, and you should check the permissions on the apt.conf.d file (chmod 644) and the absence of typos in the syntax.

Practical use cases

In practice, configuring a proxy for apt is encountered in several typical situations. The first is corporate networks with centralized traffic control, where all outgoing internet traffic from servers goes through squid or another proxy gateway, and system administrators need to uniformly set Acquire::http::Proxy on dozens or hundreds of machines via Ansible or Puppet.

The second situation is testing the availability of repositories and mirrors from different geographical locations. For example, a DevOps engineer checks how quickly the regional Ubuntu mirror serves packages from different countries or reproduces a bug related to the geoblocking of a specific repository. Here, residential proxies are convenient — they provide IP addresses from real providers in the desired region and allow you to see exactly what the end user from that country sees.

The third scenario is mass automated deployment of virtual machines and containers, where package updates go through the proxy on hundreds of instances simultaneously. Here, stability and connection speed are critical, so for such infrastructure tasks, datacenter proxies are more often used — they have lower latency and higher throughput compared to residential or mobile pools, which is important for parallel apt-get requests on a large number of hosts.

The fourth case is isolated test environments (sandbox, air-gapped environments with limited access), where the only way to the external internet is through a dedicated proxy node with strict traffic auditing. In such infrastructures, setting up via apt.conf.d with a fixed proxy IP is the only working option, and that is why it is essential to know all the nuances of the Acquire directive syntax in advance to avoid wasting time when deploying new servers.

Conclusion

Configuring a proxy for apt and apt-get in Debian and Ubuntu comes down to three working methods: a permanent config in apt.conf.d with Acquire::http::Proxy directives, temporary environment variables http_proxy/https_proxy (remembering the -E flag with sudo), and one-time parameter passing via the -o option directly in the command line. For SOCKS5 proxies, an HTTP layer like privoxy will be required, and in the case of 407 and Connection timed out errors, the first thing to check is the URL syntax and the availability of the proxy via curl.

If you are configuring a proxy for server tasks — deployment automation, testing from different regions, or controlling outgoing traffic on multiple machines — it is important to choose a proxy with stable uptime and low latency. For production infrastructure, datacenter proxies are better suited, while for tasks that require simulating real user traffic from a specific country, consider mobile proxies — they provide IPs from mobile operators and minimize the risk of blocks when accessing regional mirrors and repositories.