Installing proxyconf will solve this, but behind a proxy you can't install a plugin simply using the command vagrant plugin install, Bundler will raise an error.
set your proxy in your environment if you're using a unix like system
If your proxy requires authentication it is better to set the environment variable rather than storing your password in the Vagrantfile.
Also your Vagrantfile can be used by others easily who are not behind a proxy.
Auto detect your proxy settings and inject them in all your vagrant VM
install the proxy plugin
vagrant plugin install vagrant-proxyconf
add this conf to you private/user VagrantFile (it will be executed for all your projects) :
vi $HOME/.vagrant.d/Vagrantfile
Vagrant.configure("2") do |config|
puts "proxyconf..."
if Vagrant.has_plugin?("vagrant-proxyconf")
puts "find proxyconf plugin !"
if ENV["http_proxy"]
puts "http_proxy: " + ENV["http_proxy"]
config.proxy.http = ENV["http_proxy"]
end
if ENV["https_proxy"]
puts "https_proxy: " + ENV["https_proxy"]
config.proxy.https = ENV["https_proxy"]
end
if ENV["no_proxy"]
config.proxy.no_proxy = ENV["no_proxy"]
end
end
end
set HTTP_PROXY=http://proxy.yourcorp.com:80
set HTTPS_PROXY=https://proxy.yourcorp.com:443
Substitute the address and port in the above snippets to whatever is appropriate for your situation. The above will remain set until you close the CMD prompt. If it works for you, consider adding them permanently to your environment variables so that you won't have to set them every time you open a new CMD prompt.
The question does not mention the VM Provider but in my case, I use Virtual Box under the same environment. There is an option in the Virtual Box GUI that I needed to enable in order to make it work. Is located in the Virtual Box app preferences: File >> Preferences... >> Proxy. Once I configured this, I was able to work without problems. Hope this tip can also help you guys.
On windows, you must set a variable to specify proxy settings, download the vagrant-proxyconf plugin: (replace {PROXY_SCHEME}(http:// or https://), {PROXY_IP} and {PROXY_PORT} by the right values)
set http_proxy={PROXY_SCHEME}{PROXY_IP}:{PROXY_PORT}
set https_proxy={PROXY_SCHEME}{PROXY_IP}:{PROXY_PORT}
After that, you can add the plugin to hardcode your proxy settings in the vagrant file
However, there's quite a few things that could still go wrong.
Firstly, you probably can't install vagrant plugins when behind the proxy. If that's the case you should download the source e.g. from rubygems.org and install from source
If you solve that problem you might have the fortune of being behind an NTLM proxy, which means that if you are using *nix on your guest machines then you still have some way to go, because NTLM authentication is not supported natively
There are many ways of solving that. I've used CNTLM to solve tht part of the puzzle. It acts as glue between standard authorization protocols and NTLM
For a complete walk through, have a look at this blog entry about setting vagrant up behind a corporate proxy
If you actually do want your proxy configurations and plugin installations to be in your Vagrantfile, for example if you're making a Vagrantfile just for your corporate environment and can't have users editing environment variables, this was the answer for me:
ENV['http_proxy'] = 'http://proxyhost:proxyport'
ENV['https_proxy'] = 'http://proxyhost:proxyport'
# Plugin installation procedure from http://stackoverflow.com/a/28801317
required_plugins = %w(vagrant-proxyconf)
plugins_to_install = required_plugins.select { |plugin| not Vagrant.has_plugin? plugin }
if not plugins_to_install.empty?
puts "Installing plugins: #{plugins_to_install.join(' ')}"
if system "vagrant plugin install #{plugins_to_install.join(' ')}"
exec "vagrant #{ARGV.join(' ')}"
else
abort "Installation of one or more plugins has failed. Aborting."
end
end
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.proxy.http = "#{ENV['http_proxy']}"
config.proxy.https = "#{ENV['https_proxy']}"
config.proxy.no_proxy = "localhost,127.0.0.1"
# and so on
(If you don't, just set them as environment variables like the other answers say and refer to them from env in config.proxy.http(s) directives.)