How to Upgrade the Laravel Homestead Vagrant box

It might seem that upgrading your Laravel Homestead environment should be as easy as running vagrant box update. You probably realized something was wrong when you tried to remove the previous version of the box, and got an error like this:

Box ‘laravel/homestead’ (v0.4.0) with provider ‘virtualbox’ appears to still be in use by at least one Vagrant environment. Removing the box could corrupt the environment. We recommend destroying these environments first:

The problem is that Vagrant doesn’t know how to migrate the changes from one virtual hard drive image into another virtual hard drive image. Updating requires you to start from a new hard drive image, then reapply changes through file synchronization and database migrations/seeds. While it’s not quite as simple as running vagrant box update, it’s still pretty easy if you’ve prepared and know the commands to run.

To upgrade your Laravel Homestead environment, follow these steps:

  1. You shouldn’t have any data inside the Homestead virtual machine that can’t be recreated from other sources. You should already be using Migrations and Seeders to create your development database, and your Laravel application files should be synchronized from the host’s filesystem. If not, and there’s any data you need to preserve from the virtual machine, make a backup now and keep it somewhere outside your Homestead virtual machine.
  2. Run the vagrant box update command to download the latest version of the Laravel Homestead Vagrant box.
  3. Next run the vagrant destroy command to destroy the existing Homestead environment.
  4. Now you’re ready to run the vagrant up command, which will bring up and provision the new Homestead Vagrant environment using the latest version of the laravel/homestead box. This will also run any provisioning commands in ~/.homestead/ (for instance, to re-install packages), and also synchronize files from the host file system.
  5. Login to the Homestead virtual machine, and from your Laravel application directory, run the php artisan migrate --seed command to migrate and re-seed the database.
  6. (Optional) Find any old versions of the Homestead box by running vagrant box list, and delete them with vagrant box remove laravel/homestead --box-version version:C:\Users\David\Homestead>vagrant box list
    laravel/homstead (virtualbox, 0.4.0)
    laravel/homestead (virtualbox, 0.4.2)

    C:\Users\David\Homestead>vagrant box remove laravel/homestead --box-version 0.4.0
    Removing box ‘laravel/homestead’ (v.0.4.0) with provider ‘virtualbox’…

1 thought on “How to Upgrade the Laravel Homestead Vagrant box”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s