Edgar Latorre

I'm Edgar and this is my blog where I write about software development.

How to create an environment on vagrant to code with Rails from the scratch

09 May 2013

Considering that you have the virtual box installed, you need to create a box. In this example I’ll call our box of “development”.

Vagrant download: http://downloads.vagrantup.com/tags/v1.2.2

##The first step is to create the box:

vagrant init development http://files.vagrantup.com/precise64.box

Now we have a file called “Vagrantfile”

##The second step is to start the virtual machine

vagrant up

this proccess could take some time, because it’ll make the download of the box with ubuntu precise 64.

After the process is done, we need to map the rails’ port. We’ll edit the “Vagrantfile” and put this line on the file:

config.vm.network :forwarded_port, guest: 3000, host: 3000 #rails

Save the file and reload the vagrant with the command:

vagrant reload

##On the third step we’ll access the virtual machine by ssh:

vagrant ssh

The version of ruby in this box is 1.8.7, if you want to update to 2.0.0 follow this step:

Remove ruby 1.8.7:

sudo apt-get remove ruby

And then download the new version:

wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz

extract the folder:

tar zxvf ruby-2.0.0-p0.tar.gz

Install the basic package to compile ruby:

sudo apt-get install build-essential binutils

Compiling and install ruby:

./configure
make
sudo make install

If you don’t want to install the gems as sudoer, then you need to change the gem home:

export GEM_HOME="$HOME/.gems"
export GEM_PATH="$GEM_HOME"

you can put these lines on ~/.bashrc

get out of the box and reload:

vagrant reload

Now we have the ruby 2.0.0

The final step is to install the rails:

gem install rails

Let’s go to party!