Configure proxy for APT to download faster

As an Ubuntu user, I often retrieve softwares from PPA in addition to official Ubuntu repositories. My own QR scanner software, CoBang, is also hosted there. But one issue with PPAs is that, it is slow to download for people from developing countries like Viet Nam. We can overcome that by using a domestic proxy server.

The idea of using proxy is that, we use the Internet line at datacenter (where proxy server stays) to download files from PPA, which is fast for international connection, then the files are delivered to our home via domestic line, which is fast for domestic connection. So the requirement is that, the proxy server must be in the same country, or in near neighbor country.

If we have a VPS, we can install Dante to have a proxy server. I have another post about how to install and setup Dante. This guide applies for SOCKv5 server, like Dante. If you use another type of proxy, I cannot help.

proxy

Assume that your server has IP address 172.67.218.202, the proxy software listens at the port 1080, and you configure the proxy to require authentication, with username duck, password passw0rd. Here are what need to do.

  1. Create a file /etc/apt/apt.conf.d/proxy.conf with this content:
Acquire::https::Proxy::ppa.launchpadcontent.net "socks5h://172.67.218.202:1080";

With this config, only when downloading packages from PPA will need to use proxy.

  1. Create a file /etc/apt/auth.conf.d/proxy.conf with this content:
machine socks5h://172.67.218.202:1080
login duck
password passw0rd

This configuration tells APT how to login to our proxy.

Done. Now try doing sudo apt update / install. APT will be faster.

(Cover image is from richads.com. Credit to them)