How to setup a Ruby on Rails environment in Windows

I’ve recently had to setup a couple of RoR dev environments/toolchains in Windows. I suggest not doing this wholly inside windows, but you can still orchestrate the whole process from inside windows. Obviously OSX is a much more clean way to do rails development, but here we are. Most everyone who is anyone develops RoR using OSX, and most everyone else uses Linux. Ruby technically supports Windows, but it’s really not reccomended you go down that route. It’s easier to just setup your dev machine as  Linux VM and call it a day.

This tutorial was built with Ruby v 2.2.3 and Rails v 4.2.4 in November 2015 on Lubuntu 15.10.

I’m going to assume you can walk yourself through downloading and setup of the Virtualbox, Atom, Putty installers and at least a basic competence. Getting these packages to talk to eachother is where the real challenge fun begins, and integrating your Linux toolchain back to your Windows box (you clicked on this google search result because you’re a Windows user, right?)

We will be doing this as a high level overview

A) Setup Linux Box VM
B) Setup Putty/Atom/rmate in Windows
C) Setup Ruby on Rails in Linux
D) Setup Remote Desktop Server in Linux

So, you will need

  1. A way to virtualize an ubuntu box. This can be something fancy like a home VM lab, but more often you will see people running VirtualBox. I’ll leave this part up to you. Virtualbox is very convenient. I used a Hyper-V VM but as long as you can ping it’s hostname you are good to go.
  2. Linux ISO. I reccomend lubuntu (low-end Ubuntu) but you can roll with whatever you want. In this case I am using Lubuntu 15.10 desktop. Generally I like server ISOs but rails likes serving to localhost so it is convenient to be on the desktop of the localhost with a GUI editor like Atom and a browser like Firefox (preferably Chrome), so pick a desktop “distro”. Ubuntu is built on top of Debian and between Debian and Ubuntu there’s enough documentaiton on the web now that you can work through any problem by simply pasting your error message in to google.
  3. A command line tool for Windows. Putty works great.
  4. A text editor. I like Notepad++ but Atom is the new gun in town and has support for things like the package remote-atom so you can edit files on your local PC.

A) Setup Linux box VM

Install Virtualbox. Create a new VM, under “network adapter” set the adapter type to “allow bridge”. Give the VM LOTS of RAM and max out the number of CPUs you can give it (typically 2-4). More memory & more cpu = faster install, better GUI response, etc. Start VM, install Lubuntu from ISO. ( http://lubuntu.net/ )

B) Setup Putty/Atom in Windows, rmate in Linux

On your new Lubuntu VM, install SSH server from the GUI (start->System Tools->LX Terminal)

sudo apt-get install screen # this is super helpful in keeping your session alive
screen
<enter>
sudo apt-get install openssh-server vino -y
curl -o /usr/local/bin/rmate https://raw.githubusercontent.com/aurora/rmate/master/rmate
sudo chmod +x /usr/local/bin/rmate
mv /usr/local/bin/rmate /usr/local/bin/ratom
Install Putty on Windows ( www.chiark.greenend.org.uk/~sgtatham/putty/download.html )

From here: ( https://blog.cs.wmich.edu/sublime-text-putty-and-you/ )
Launch putty, insert hostname, then from the Left Nav choose “SSH”, “Tunnels”, Add new forwarded port:
Source Port: 52698
Destination: localhost:52698
Choose radio buttons: Auto, Remote
Save your putty session (suggested)
Connect, login with your Linux user/password

Install Atom on Windows ( https://atom.io/ )

Install Atom package “remote-atom”
Go to Packages->Remote Atom->Start Server

In Putty type rmate test.txt
If everything has been setup correctly, your should be able to see the opening file in Atom on your Windows desktop.

C) Install Ruby

On linux box from Putty:

From here: ( https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04 )

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo ‘export PATH=”$HOME/.rbenv/bin:$PATH”‘ >> ~/.bash_profile
echo ‘eval “$(rbenv init -)”‘ >> ~/.bash_profile
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo ‘export PATH=”$HOME/.rbenv/plugins/ruby-build/bin:$PATH”‘ >> ~/.bash_profile
source ~/.bash_profile
cp .bash_profile .bashrc

rbenv install -v 2.2.3
rbenv global 2.2.1
ruby -v
echo “gem: –no-document” > ~/.gemrc
gem install bundler
gem install rails
rbenv rehash
rails -v
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

Ruby on Rails is installed! Let’s build a test app and see if it works

cd ~
rails new testapp
rake db:create
ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s/\/.*$//’
rails server –binding=server_public_IP

Browse to: http://server_public_IP:3000

NOTE: to end your webserver type ctrl+c

D) Setup remote desktop (so you can use your VM from your windows box easily)

From here: ( http://askubuntu.com/questions/580415/how-to-remote-desktop-from-windows-to-lubuntu )

sudo apt-get install xrdp
sudo nano /etc/xrdp/startwm.sh # just confirm the last line says this: . /etc/X11/Xsession
. /etc/X11/Xsession
sudo nano ~/.xsession # type in this: lxsession -e LXDE -s Lubuntu
lxsession -e LXDE -s Lubuntu
sudo service xrdp restart # will make it pick up changes
Connect to your host using RDP (remote desktop) and login using your linux username and password

 

This entry was posted in computing, linux and tagged , , , , , , . Bookmark the permalink.

One Response to How to setup a Ruby on Rails environment in Windows

  1. Artur Kuchin says:

    Greetings from Moscow!

    Many thanks for this one:
    http://nearlydeaf.com/?p=1145

    And this:
    http://nearlydeaf.com/?p=1149

    Have a nice day!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>