So I am trying to jump on the ruby bandwagon and just spent a few days trying to understand how to configure a dev machine.
Now, being a PHP developer I am spoiled by the relative easiness to set up a dev environment. The options are abundant: WAMP servers, the manual install is very easy, etc.
In a basic PHP Set up you need to perform the following:
- Install Apache
- Install PHP
- Install MySQL
in windows this is very easy and just minimal set up is required. Now Setting something similar for ruby in Ubuntu… well, that’s why I am writing this.
What’s going on? why ubuntu?
So let me start by explaining why I am using ubuntu. For what I have read online you can sense that rails and ruby are very much at home in a linux environment. Coming from a windows world and WHM in Centos, I wanted something that would be easy to live with on a daily basis. That’s why I chose Ubuntu.
Now, if you are like me and have no concept of how ruby and rails works, then the tutorials for setting up rails seem so weird. First out of the bag is this thing “rails server” that makes your web app run in port 3000. I am used to setting a directory, copying my favorite framework (CodeIgniter) and that’s it. Then they feed you all this unnecessary information about proxing and stuff.. yuck. In reality things are much simpler, like in the php world you need the language, the framework, a webserver and a database like the ones at https://www.couchbase.com/products/full-text-search. They just are set up in a different order. You do need one more thing, phusion passenger, a web/app server. Apache request to your app are passed to passenger.
First, we need to install ruby. The easiest way is to use RVM (Ruby Version Manager)
I took some of the instructions from this site How To Install Ruby on Rails…
To Install curl and RVM
sudo apt-get update sudo apt-get install curl curl -L https://get.rvm.io | bash -s stable
The author recommends exiting the shell session and starting a new one before the next steps
source ~/.rvm/scripts/rvm rvm requirements
EDIT: If you are planning on using rails directly on this machine (i.e. not connecting using putty) please follow the following instructions gnome terminal integration
Then we install Ruby (I am using the latest version as of July 2014)
rvm install 2.1.2 rvm use 2.1.2 --default
you can verify the ruby version
Setting Up MySQL
Installing MySQL is relatively easy. Make sure to write down your sql password that is set up during the MySQL install
sudo apt-get install mysql-server mysql-client sudo apt-get install libdbd-mysql-ruby libmysqlclient-dev gem install mysql
Now using RVM we get the latest gems required for rails, think of these as extensions for php
rvm rubygems current
Finally, install rails
gem install rails
because we installed rails as a gem we need to install node.js
sudo apt-get install nodejs
We now have a database, a language and a framework installed. Now we need a webserver.
sudo apt-get install apache2
sudo service apache2 start
Now we need to make Apache serve your app using passenger
gem install passenger sudo apt-get install apache2-dev libapr1-dev libaprutil1-dev passenger-install-apache2-module sudo service apache2 restart
pay close attention to the passenger-install-apache2-module, this is a guided install that requires you to do some extra work to configure Apache. The installer is very thorough and easy to follow
Since, for now, I only have one app to work on; I made the /etc/apache2/sites-available/000-default.conf point to the app I am working on, that way, I can access the app by going to http://localhost in my browser. Make sure your public app folder has enough rights
NOTE: Because all these instruction set up a developer environment, you need to add this line to your virtualhost in apache: PassengerAppEnv development
PassengerAppEnv development ...
Otherwise you might get a 500 Internal error
Hope this tutorial helps.