I think one of the trickiest thing with Rails is getting started. I did play around with it a few times on OSX and Windows and the installation was never that simple. If you want to get into PHP you can just do it by installing LAM, MAMP or uploading your php file to a web server. Ruby requires a bit more preparation.
Here come my first difficulty with Ruby on Rails. The internet is flooded with tutorials, articles, how-tos on the installation of RoR. My experience is that it can be a great advantage and also disadvantage as sometimes it is quite difficult to find the right one.
Ruby and Rails are constantly developing. Considering the frequent version upgrades and the various operation systems, it is quite difficult to produce a ‘good for all’ guideline. Therefore I think it is useful to write down how I managed to get Ruby and Rails rolling on my Ubuntu 11.10. Anyway I want to document here my whole learning process and it was indeed a part of it.
I have a Lenovo N500 laptop and recently installed the new Ubuntu 11.10. I’m quite happy with it and want to have this machine as a development machine.
So we have two choices here, installing ruby and rails on the system or we can go via the rvm or Ruby Version Management. This is what we should choose.
RVM is good for you. RVM gives the flexibility as you can install the whole Ruby stuff in your personal space so it is very easy to play around with dangerous, cutting edge, hot new stuff and wipe the whole thing off when it blows up. RVM also makes it possible to switch between ruby and rails versions and set gemsets. This meant to be useful as well. We will figure it out later.
We work in the terminal window. The installation is pretty easy, first we start out with the download of some basic apps and then installing rvm and ruby and rails via rvm. Here are the steps, just type them in to your terminal, one after the other.
sudo apt-get update sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqllite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
Here we got some applications we will need to work with Rails. sqlite3, mysql for database access, etc.
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc source ~/.bashrc
Now that we set some routes, time to install ruby and the gems via RVM.
rvm install 1.9.2 rvm use 1.9.2 --default gem -v gem update --system rvm ruby-1.9.2-p290@rails31 --create --default rvm gemset list gem list
Whe I first tried to install RoR, I ran into some weird error messages at the end and could not figure out. Because I did not know one thing and the article did not mention it.
They could have saved me some headache with this information. Anyway, following the guideline, I went for Node.js
sudo apt-get install nodejs gem install rake rake --version gem install rails
That’s it! You are good to go. We will need something for our databases (sqlite3, mysql) but now we are good. Just type in…
rails new myapp cd myapp rails server
Now the WEBRICK server message should appear and if you navigate to http://localhost:3000 in your browser, you should see your first Ruby on Rails application running. Congratulations.