Vagrant: Fixing “error while downloading the metadata for this box”

If you see the message, “There was an error while downloading the metadata for this box”, with a 404 not found return message when doing a box update – make sure to check the URL listed in the Vagrant “metadata_url” files.

For example, the “atlas.hashicorp.com” host has been deprecated in favor of “vagrantcloud.com” for some basic hosts such as ubuntu/trusty64.  If you created this host before the change, this older URL would still be in your metadata_url file and you would be expected to see this error.

There is a “metadata_url” file for each individual box at “$VAGRANT_HOME/boxes/*/metadata_url”.

Below is a sed command that replaces all the instances of atlas.hashicorp with vagrantcloud.

sed -i -- 's/atlas.hashicorp/vagrantcloud/g' ~/.vagrant.d/boxes/*/metadata_url

After this command, the “vagrant box update” should work without error.

Warning  about newline in metadata_url

NOTE: If you modify these files with vi or other editors, it will by default put an end-of-line character at the end of the first line, which will cause vagrant to show a “Illegal characters found in URL” message.  To avoid this behavior in vim, you can edit in binary mode (vim -b metadata_url).

If an editor modifies these files incorrectly, you can fix it with the following command which removes the newline character.

find ~/.vagrant.d/boxes -name metadata_url | xargs perl -i -pe 'chomp if eof'

 

 

REFERENCES

https://github.com/hashicorp/vagrant/issues/9442 (describes deprecation of atlas.hashicorp)

https://github.com/laravel/homestead/issues/807 (describes deprecation of atlas.hashicorp)