- Install VirtualBox https://www.virtualbox.org/
- Install Vagrant https://www.vagrantup.com/
- Install Git for Windows https://git-scm.com/download/win - this will also install MinGW shell
To run shell, press the Windows Key and run git bash
- Initialize Vagrant using
vagrant init
- Install a box. E.g. Ubuntu 16.04 https://atlas.hashicorp.com/ubuntu/boxes/xenial64
- Configure your VM by editing
Vagrantfile
. Share the network using config:
config.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: "127.0.0.1"
This will forward everything from the guest VM port 3000 to the host port 3000. So you'll be able to access http://localhost:3000 on a Windows browser and it will load your Rails app running in the VM.
Running a Rails application from within Vagrant is really slow because the VirtualBox sync'd folder system has performance issues. You need to use NFS. The official Vagrant website will say that it does not support NFS on Windows. So you have to install a plugin.
Install https://github.com/winnfsd/vagrant-winnfsd by following the instructions.
Add to your settings:
config.vm.synced_folder ".", "/vagrant", type: 'nfs'
config.vm.network "private_network", type: "dhcp"
- You
git clone
and all git commands in the VM to the shared folder. - Do all editing on Windows with your favourite code editor.
- Your entire server stack is running on the VM. You run the actual application within Vagrant. So SSH in using
git bash
, and thenvagrant ssh
into your VM, and run all your rails commands. E.g.bundle exec rails s
. - You test using your browser on Windows - E.g. using Edge, Chrome, Firefox visit http://localhost:3000