Skip to content

Instantly share code, notes, and snippets.

@leonardteo
Last active March 14, 2018 23:14
Show Gist options
  • Save leonardteo/d2928258be7302fc539ad8a3271499a2 to your computer and use it in GitHub Desktop.
Save leonardteo/d2928258be7302fc539ad8a3271499a2 to your computer and use it in GitHub Desktop.
How to get Rails dev environment working on Windows 10

How to get a Rails dev environment working on Windows 10

Base setup

  1. Install VirtualBox https://www.virtualbox.org/
  2. Install Vagrant https://www.vagrantup.com/
  3. 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

Set up dev environment

  1. Initialize Vagrant using vagrant init
  2. Install a box. E.g. Ubuntu 16.04 https://atlas.hashicorp.com/ubuntu/boxes/xenial64
  3. 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.

The tricky part

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"

How your development workflow works

  1. You git clone and all git commands in the VM to the shared folder.
  2. Do all editing on Windows with your favourite code editor.
  3. Your entire server stack is running on the VM. You run the actual application within Vagrant. So SSH in using git bash, and then vagrant ssh into your VM, and run all your rails commands. E.g. bundle exec rails s.
  4. You test using your browser on Windows - E.g. using Edge, Chrome, Firefox visit http://localhost:3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment