Search code examples
vagrantvagrantfilevagrant-windows

Can I manually download a vagrant box file and use it? If so , how?


I was doing my relational database course from UDACITY when they asked me to download VirtualBox and vagrant. They then gave me a folder. I was supposed to navigate inside the folder and then run vagrant up so that it downloads ubuntu 16.04. I tried that but everytime it gets cancelled due to low internet speeds. Is there any way I can download the file on my own using IDM probably and then configuring it myself? Please link me to any site or anything that can help me. I will post the code inside the VagrantFile below

And yeah Im using windows 10 if that helps

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04-i386"
config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: 
"127.0.0.1"
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: 
"127.0.0.1"
config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: 
"127.0.0.1"

# Work around disconnected virtual network cable.
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
end

config.vm.provision "shell", inline: <<-SHELL
apt-get -qqy update

# Work around https://github.com/chef/bento/issues/661
# apt-get -qqy upgrade
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-
confdef" -o Dpkg::Options::="--force-confold" upgrade

apt-get -qqy install make zip unzip postgresql

apt-get -qqy install python3 python3-pip
pip3 install --upgrade pip
pip3 install flask packaging oauth2client redis passlib flask-httpauth
pip3 install sqlalchemy flask-sqlalchemy psycopg2 bleach requests

apt-get -qqy install python python-pip
pip2 install --upgrade pip
pip2 install flask packaging oauth2client redis passlib flask-httpauth
pip2 install sqlalchemy flask-sqlalchemy psycopg2 bleach requests

su postgres -c 'createuser -dRS vagrant'
su vagrant -c 'createdb'
su vagrant -c 'createdb news'
su vagrant -c 'createdb forum'
su vagrant -c 'psql forum -f /vagrant/forum/forum.sql'

vagrantTip="[35m[1mThe shared directory is located at /vagrant\\nTo 
access your shared files: cd /vagrant[m"
echo -e $vagrantTip > /etc/motd

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
make install

echo "Done installing your virtual machine!"
SHELL
end

Solution

  • You can manually download the box file (normally vagrant should save under ~/.vagrant.d/tmp/ previous attempt to download box so it should not restart from 0)

    Once you have downloaded the file, you need to add the box to your vagrant config:

    $ vagrant box add --name <name of the box> --box-version <version of the box> <downloaded box file>
    

    Make sure you name the box correctly (the same way it is define from the original Vagrantfile) you can check the box version from the url of the downloaded box

    For example, ubuntu/xenial64 latest version is 20170717.0.0 so if you were to download this box, you would download this version.