Ruby On Rails Envy – how to set up a ROR environment (with BitNami)
August 8, 2010
From the moment I read about ScottGu sitting in a plane and setting the outline for ASP.NET MVC, I couldn't help thinking: "This is a serious case of Ruby On Rails Envy." I know, the MVC pattern is very old indeed, but I thought it is more than coincidental that, with the success of ROR, Microsoft comes up with an alternative. Oh well. Just my humble opinion.
I was writing webapplications with the Ruby on Railsframework back then (I think it is 2008) but as ASP.NET MVC matured I switched. Because the companies I work for do have a Windows environment ready for me, so practically I had to. And I never looked back at ROR. Which is a shame, because Ruby.Is.Beatiful.
So let's get our hands dirty and get started with Ruby On Rails!
But wait. What? Where? How?
Setting up the Rails environment
If you are on a Mac or on Linux it's relatively easy to set up a Rails environment. If you're on Windows it is less comfortable, because it's slow. And as for editing, when you're on a Mac, the TextMate editor is the absolute bomb.
My MacBook is in the living room playing Spotify songs at the moment, so let's take the Linux road today in a virtual environment. Let's use vim as a texteditor.
This is going to be lots of fun!
Yeah, okay, but I'm a bit lazy and after all, it's Sunday evening.
Right. Let's download a virtual machine that runs Ubuntu Server with a complete Ruby environment. Please do so and we'll start the tutorial from there.
After booting the virtual machine, this what you'll see:
Basic Linux housekeeping for starters:
sudo -s apt-get update apt-get upgrade # install the vim editor apt-get install vim # set the network interface: vim /etc/network/interface
Now the interfaces file opens. The IP address is set to dhcp by default, which we'll change to static.
Hit the INSERT key to edit the file:
# The primary network interface auto eth0 iface eth0 inet static address 192.168.201.6 netmask 255.255.255.0 network 192.168.201.0 broadcast 192.168.201.255 gateway 192.168.201.1
Now hit ESCAPE followed by :w and :q (for writing and quitting vim).
Set the DNS Server in /etc/resolv.conf:
vim /etc/resolv.conf nameserver 126.96.36.199 nameserver 188.8.131.52
Now it's time to restart the network:
Now check with ifconfig if eth0 has the correct IP address. Because if this is the case, we can leave the VMWare console for what it is and connect to the virtual machine using Putty.
Oh. Apparently ssh is disabled on the virtual machine. Go:
mv /etc/init/ssh.conf.back /etc/init/ssh.conf start ssh
Now we can connect to the appliance using Putty.
Accept the fingerprint securitywarning and login with bitnami and your password. Switch to root immediately with sudo -s (I always do so).
Eeuw, this is so boring. Where are those fancy dircolors? (Note: in some versions the dircolors are already enabled)
cd /home/bitnami vim .bashrc #paste this in the file: if [ "$TERM" != "dumb" ]; then [ -e "$HOME/.dircolors" ] && DIR_COLORS="$HOME/.dircolors" [ -e "$DIR_COLORS" ] || DIR_COLORS="" eval "`dircolors -b $DIR_COLORS`" alias ls='ls --color=auto' #alias dir='ls --color=auto --format=vertical' #alias vdir='ls --color=auto --format=long' fi
that's much better.
So, how about Ruby On Rails then?
The Bitnami Ruby Stack came with an example project. Let's start that up and check it out:
cd /opt/bitnami/projects/rubystack-2.1-0 #start the app: ruby script/server -bash: ruby: command not found
Hmm, that's not working. We should add Ruby to the path.
vim /etc/environment #hit INSERT to edit: PATH="/opt/bitnami/ruby/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" #hit ESCAPE followed by :w and :q
Now log off, log on and try again:
root@linux:/opt/bitnami/projects/rubystack-2.1-0# ruby script/server => Booting Mongrel => Rails 2.3.5 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server
And now we can access the application at http://your-vm-ip:3000.
So, everything works apparently. Next time we are going to create our first ROR project.