Configure apt to use proxy in vagrant box

Solution 1:

Its possible that apt is using squid for all its requests, but squid isn't caching the results. You could verify this by sniffing traffic, or shutting down squid while apt is downloading packages and seeing if they fail. What is the maximum_object_size in your squid configuration?

Solution 2:

Even though your problem might be in the squid config, to answer to the topic, there is now vagrant-proxyconf plugin. You can install it via:

vagrant plugin install vagrant-proxyconf

With it you can specify the Apt proxy globally in $HOME/.vagrant.d/Vagrantfile without the need to use shell provisioners in all project specific Vagrantfiles.

Example:

Vagrant.configure("2") do |config|
  config.apt_proxy.http  = "http://10.0.2.2:3128"
  config.apt_proxy.https = "http://10.0.2.2:3128"
end

or default proxy configuration:

Vagrant.configure("2") do |config|
  if Vagrant.has_plugin?("vagrant-proxyconf")
    config.proxy.http     = "http://192.168.0.2:3128"
    config.proxy.https    = "http://192.168.0.2:3128"
    config.proxy.no_proxy = "localhost,127.0.0.1,.example.com"
  end
  # ... other stuff
end