{"id":1160,"date":"2026-12-05T22:31:29","date_gmt":"2026-12-05T20:31:29","guid":{"rendered":"https:\/\/mexela.com\/blog\/apt-proxy-ubuntu-debian\/"},"modified":"2026-12-05T22:48:11","modified_gmt":"2026-12-05T20:48:11","slug":"apt-proxy-ubuntu-debian","status":"publish","type":"post","link":"https:\/\/mexela.com\/blog\/apt-proxy-ubuntu-debian\/","title":{"rendered":"How to Run apt update Behind a Proxy on Ubuntu and Debian"},"content":{"rendered":"<p>Test your approved proxy with one <code>apt-get update<\/code> before changing the machine\u2019s APT configuration. The command refreshes package indexes; it does not install or upgrade packages. Ubuntu and Debian use the same APT configuration keys here. The test described below ran on Ubuntu; the syntax is also documented by Debian.<\/p>\n<h2 id=\"apt-one-command\">Use an APT proxy for one update<\/h2>\n<p>Set <code>MEXELA_APT_PROXY<\/code> to the approved proxy URL, including its scheme and port, without embedding a password in the command. Run in a shell already authorized to refresh APT indexes. Your administrator may require elevation on a normal Ubuntu or Debian installation; follow local policy rather than copying the example into a root profile.<\/p>\n<pre id=\"apt-transient\"><code class=\"language-bash\">: \"${MEXELA_APT_PROXY:?Set the approved proxy URL first}\"\napt-get -o Acquire::http::Proxy=\"$MEXELA_APT_PROXY\" \\\n  -o Acquire::https::Proxy=\"$MEXELA_APT_PROXY\" \\\n  -o APT::Update::Error-Mode=any update<\/code><\/pre>\n<p>The configuration keys name the repository transport. An HTTPS repository can use an approved proxy whose URL starts with <code>http:\/\/<\/code>; that URL describes how APT connects to the proxy. The example uses strict update error handling so a partial failure is not mistaken for a clean refresh.<\/p>\n<h2 id=\"apt-persist\">Make the setting persistent only if the proxy is standard<\/h2>\n<p>If the proxy is required by policy, ask the administrator to place these two lines in a dedicated APT fragment such as <code>\/etc\/apt\/apt.conf.d\/80local-proxy<\/code>, preserving existing settings. Replace the template host and port. <a href=\"https:\/\/manpages.debian.org\/bookworm\/apt\/apt-transport-http.1.en.html\">Debian\u2019s APT transport documentation<\/a> covers host-specific rules and the separate authentication file; do not put credentials in a shared configuration fragment.<\/p>\n<pre id=\"apt-persistent\"><code class=\"language-text\">Acquire::http::Proxy \"http:\/\/proxy.example.com:3128\/\";\nAcquire::https::Proxy \"http:\/\/proxy.example.com:3128\/\";<\/code><\/pre>\n<p>To verify that APT reads the fragment, run without the two command-line proxy overrides:<\/p>\n<pre id=\"apt-normal-update\"><code class=\"language-bash\">apt-get -o APT::Update::Error-Mode=any update<\/code><\/pre>\n<h2 id=\"apt-on-error\">Read the error before changing repositories<\/h2>\n<table>\n<thead>\n<tr>\n<th>Observation<\/th>\n<th>Next check<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>407 Proxy Authentication Required<\/td>\n<td>Confirm the approved proxy account and method.<\/td>\n<\/tr>\n<tr>\n<td>404 or no Release file<\/td>\n<td>Check the repository URL, suite and mirror. A proxy may have carried the request correctly.<\/td>\n<\/tr>\n<tr>\n<td>Certificate or repository-signature failure<\/td>\n<td>Check the approved CA, repository signing key and system time. Keep TLS and repository signature verification enabled.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>If APT works on the host but fails in a container build, inspect the build\u2019s own proxy configuration. The <a href=\"\/blog\/docker-proxy-configuration\/\">Docker proxy guide<\/a> separates the build, daemon and container. See the <a href=\"\/blog\/proxy-setup-developer-guides\/\">developer integration hub<\/a> for other package managers and clients.<\/p>\n<p><strong>Verification, December 5, 2026:<\/strong> The transient command and persistent fragment were run with the real APT client on Ubuntu and a disposable signed repository through a loopback proxy. A changed signature and an HTTP 407 were each rejected. No packages were installed, and no public repository was contacted.<\/p>\n<p><!-- mexela-semrush-apt-single-mirror-diagnostic-20261206:start --><\/p>\n<section aria-labelledby=\"apt-only-one-repository-fails\">\n<h2 id=\"apt-only-one-repository-fails\">What if only one APT repository fails?<\/h2>\n<p>Identify the repository hostname and its HTTP or HTTPS scheme in the failed update. Check your APT configuration for that exact host as well as the default proxy settings. A host-specific rule can select a different proxy or an approved direct connection, so a successful update from another mirror cannot establish the route to this one. If the mirror redirects, record the final hostname too.<\/p>\n<p>Inspect the configuration locally with <code>apt-config dump<\/code> in the same execution environment. Its output can contain internal addresses or credentials, so share only the relevant key names, a redacted host label, and the error. Leave any intentional exceptions with their owner. See the <a href=\"https:\/\/manpages.debian.org\/bookworm\/apt\/apt-transport-http.1.en.html\">Debian APT transport reference<\/a> for host-specific settings.<\/p>\n<\/section>\n<p><!-- mexela-semrush-apt-single-mirror-diagnostic-20261206:end --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Configure an approved HTTP proxy for APT on Ubuntu or Debian. Compare a one-command override with apt.conf.d and diagnose proxy and repository errors.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189],"tags":[],"_links":{"self":[{"href":"https:\/\/mexela.com\/blog\/wp-json\/wp\/v2\/posts\/1160"}],"collection":[{"href":"https:\/\/mexela.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mexela.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mexela.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mexela.com\/blog\/wp-json\/wp\/v2\/comments?post=1160"}],"version-history":[{"count":0,"href":"https:\/\/mexela.com\/blog\/wp-json\/wp\/v2\/posts\/1160\/revisions"}],"wp:attachment":[{"href":"https:\/\/mexela.com\/blog\/wp-json\/wp\/v2\/media?parent=1160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mexela.com\/blog\/wp-json\/wp\/v2\/categories?post=1160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mexela.com\/blog\/wp-json\/wp\/v2\/tags?post=1160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}