How to setup Ruby on Rails on Ubuntu Linux

There are a lot of guides that do exactly the same as what i’m about to write about… the reason for this quick blog post is mostly a brain dump for myself.. but also because I always struggle to find up to date info for all of this in one place… and there are always gaps… So here goes! by the end of this short tutorial, you should have not only a working rails and ruby installation, running as a user, but also a ruby on rails hello world! whaaaaaat.

Firstly, install some Linux distro, I would strongly recommend Ubuntu 12.04 LTS for the purpose of this tutorial, as its supported until 2017 (at least) and I know that all the bits and pieces work if you follow this guide 🙂

On your brand new vanilla system, you’ll firstly need a few things to get up and running, some of this isn’t essential, but you’re gonna need if if you’re ever gonna write more than a hello world!

~# sudo apt-get update && sudo apt-get upgrade && sudo apt-get install build-essential curl nodejs nodejs-dev

Now you’re gonna need rvm, for those who don’t know what rvm is… google it, but essentially, it’ll manage your ruby installation, versions + much more, it tends to be the recommended approach to installing and managing ruby, whats more… you can run and switch rubies locally all in the context of your user 🙂

~# curl -L https://get.rvm.io | bash -s stable

Once thats finished doing its thing.. (shouldn’t take long) you’ll need to tell your shell about it and re-login.

~# source ~/.rvm/scripts/rvm && exit

Its important you do actually re-login, as otherwise you’re gonna have problems when you try to tell rvm which ruby you wanna use. Now you’re thinking… hmm… what about the 1001 dependencies I need… Well, did I mention rvm 🙂 The following 3 commands will find and install dependencies (note, you may have to pre-pend sudo to the first command). Install Ruby, Gems and finally Rails… (that was fast right?).

~# rvm requirements /OR/ ~# sudo rvm requirements
~# rvm install ruby (note: you can specify a version here if you wish.. i.e. 1.9.3)
~# rvm use ruby --default
~# rvm rubygems current

Now we’ve got all that sorted out, lets use gem, provided by rvm, to install rails…

~# gem install rails

At this point, providing you didn’t encounter any errors, you now have a fully working ready to rock’n’roll ruby on rails setup that supports switching versions, updates + more.

But what about that hello world?… Ah, thats easy 🙂

~# rails new Hello
~# cd Hello && rails s

Now visit http://yourip:3000 to see the lovely Ruby Welcome Aboard page…

Stay tuned for more RoR love as I learn it myself!

 

 

Leave a Reply