135

How do I add a downloaded .box file to Vagrant's list of available boxes? The .box file is located on an external drive.

I tried running vagrant box add my-box d:/path/to/box, but Vagrant interprets the path as a URL.

Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
  • Could you post the whole output along with vagrant version? Theoretically vagrant box add should work like a charm with local file paths – Emyl Feb 27 '14 at 14:14
  • 3
    I'm in Ubuntu, and `vagrant box add my-box /path/to/file.box` worked fine for me. – maan81 Mar 25 '15 at 23:05

8 Answers8

205

Solution:

vagrant box add my-box file:///d:/path/to/file.box

Has to be in a URL format.

Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
  • 8
    what if i use `vagrant box add my-box ./path/to/mybox.box ?` – Rakib Sep 15 '15 at 10:53
  • you can also pass `-f` to force it to download the box again, and replace it if it already exists. e.g. `vagrant box add -f my-box http://some-url` – Brad Parks Nov 17 '16 at 14:20
  • vagrant under macos and linux (2.2.2) works with a nun URI path to, so the scheme file:// can be omitted here at least. Maybe that a version specific change or its windows specific, i rather expect the latter one – Eugen Mayer Nov 11 '18 at 13:14
104

You can point to the folder where vagrant and copy the box file to same location. Then after you may run as follows

vagrant box add my-box name-of-the-box.box
vagrant init my-box
vagrant up

Just to check status

vagrant status
Sameera Thilakasiri
  • 9,452
  • 10
  • 51
  • 86
  • i did `vagrant init` and `vagrant up` and my vagrant box is running. But i can't ssh. When i do `vagrant ssh` it says "The machine you're attempting to SSH into is configured to use password-based authentication. Vagrant can't script entering the password for you. If you're prompted for a password, please enter the same password you have configured in the Vagrantfile." whereas i didn't configure anything in the `Vagrantfile`. I am just using the `Vagrantfile` that got automatically created upon `vagrant init`. When i `cat Vagrantfile`, I don't see anything called a password or pem or anything – Rakib Sep 15 '15 at 12:31
  • If `vagrant ssh` is asking for a password, and the base box you're using is public, chances are the password is `vagrant`. – codewario Jan 04 '17 at 01:33
  • I have the same error and password vagrant didn't solve it – Karim Samir Feb 24 '17 at 20:29
  • The password for the [modern.ie](https://modern.ie) Microsoft boxes is `Passw0rd!` – Redsandro Oct 20 '18 at 23:12
  • To everybody who cannot ssh afterwards, the problem originates from the box export. You need to add the Vagrant insecure public key to the authorized keys again. See https://stackoverflow.com/questions/30075461/how-do-i-add-my-own-public-key-to-vagrant-vm – MakisH Apr 28 '21 at 12:17
28

Try to change directory to where the .box is saved

Run vagrant box add my-box downloaded.box, this may work as it avoids absolute path (on Windows?).

Terry Wang
  • 13,840
  • 3
  • 50
  • 43
  • i did `vagrant init` and `vagrant up` and my vagrant box is running. But i can't ssh. When i do `vagrant ssh` it says "The machine you're attempting to SSH into is configured to use password-based authentication. Vagrant can't script entering the password for you. If you're prompted for a password, please enter the same password you have configured in the Vagrantfile." whereas i didn't configure anything in the `Vagrantfile`. I am just using the `Vagrantfile` that got automatically created upon `vagrant init`. When i `cat Vagrantfile`, I don't see anything called a password or pem or anything – Rakib Sep 15 '15 at 12:32
11

Alternatively to add downloaded box, a json file with metadata can be created. This way some additional details can be applied. For example to import box and specifying its version create file:

{
  "name": "laravel/homestead",
  "versions": [
    {
      "version": "7.0.0",
      "providers": [
        {
          "name": "virtualbox",
          "url": "file:///path/to/box/virtualbox.box"
        }
      ]
    }
  ]
}

Then run vagrant box add command with parameter:

vagrant box add laravel/homestead /path/to/metadata.json
Jakhongir
  • 586
  • 8
  • 11
10

Solution for Windows:

  • Open the cmd or powershell as admin
  • CD into the folder containing the .box file
  • vagrant box add --name name_of_my_box 'name_of_my_box.box'
  • vagrant box list should show the new box in the list

Solution for MAC:

  • Open terminal
  • CD into the folder containing the .box file
  • vagrant box add --name name_of_my_box "./name_of_my_box.box"
  • vagrant box list should show the new box in the list
langlauf.io
  • 3,009
  • 2
  • 28
  • 45
5

First rename the Vagrantfile then

vagrant box add new-box name-of-the-box.box
vagrant init new-box
vagrant up

Just to check status

vagrant status

that's all

Ashfaq
  • 269
  • 2
  • 10
3
F:\PuppetLab\src\boxes>vagrant box add precise32 file:///F:/PuppetLab/src/boxes/precise32.box
==> box: Adding box 'precise32' (v0) for provider:
    box: Downloading: file:///F:/PuppetLab/src/boxes/precise32.box
    box: Progress: 100% (Rate: 1200k/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'precise32' (v0) for 'virtualbox'!
Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
bhapat
  • 41
  • 1
1

Just to add description for another one case. I've got to install similar Vagrant Ubuntu 18.04 based configurations to multiple Ubuntu machines. Downloaded bionic64 box to one using vagrant up with Vagrantfile where this box was specified, then copied folder .vagrant.d/boxes/ubuntu-VAGRANTSLASH-bionic64 to others.

Dmitriy Vinokurov
  • 365
  • 1
  • 6
  • 28