Sunday, February 2, 2014

Install Rails 4 with RVM and Ruby 2.1.0 on Ubuntu 13.10

I noticed Ruby 2.1 wasn't available for Ubuntu 13.10 yet, so I decided to post this really fast set of install steps on how I did this.

It will have to build from source, so first make sure you have everything you need and are up to date.

In your shell:

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev

For RVM:

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev

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



RVM tells you type this when you are done:

source ~/.rvm/scripts/rvm

You might have to add that to your .bashrc if this is your first time installing this. I did not there was an entry in my .bashrc already.

Now when I check my ruby version:

ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]


And my gem version:

gem -v
2.2.1


If you don't want to store the documentation for each gem package locally:

echo "gem: --no-ri --no-rdoc" > ~/.gemrc

I'm going to install node.js as well to support Coffeescript:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
The last line after this install for me says:

Setting up nodejs (0.10.25-1chl1~saucy1) ...

Rails installs a lot of gems, so this could take a little while depending on your computer.

To install rails:

gem install rails

Now check the version:
rails -v
Rails 4.0.2


At this point you are done. You can use Rails with sqlite3. I personally don't do that because I use mysql, which I already have installed. But just in case you don't and you would want Mysql here are the instructions. If you have mysql but not the dev library you should run this line anyway, so you can compile the mysql2 gem.

Install mysql:

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

This is optional but gets workbench v 5.2.47 which I am fine with. There is a 6.x version on the mysql website.
sudo apt-get install mysql-workbench

No compile the mysql2 gem. This isn't required here, but will make it easier to check your on track:

gem install mysql2

Now create your new app:
rails new yourappname -d mysql

You have mysql based rail application at this point. If you are really new to rails, you want to know to do these couple of things:

cd yourappname
Modify the config/database.yml for username and password
rake db:create
rails server
Your application is now running on http://localhost:3000

Without comments and shrinking the steps down to be even shorter, I think it could look something like this:

sudo add-apt-repository ppa:chris-lea/node.js

sudo apt-get update

sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libgdbm-dev libncurses5-dev automake libtool bison libffi-dev nodejs mysql-server mysql-client libmysqlclient-dev mysql-server mysql-client libmysqlclient-dev

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

source ~/.rvm/scripts/rvm

echo "gem: --no-ri --no-rdoc" > ~/.gemrc

gem install rails

rails new yourappname -d mysql

cd yourappname

Modify the config/database.yml for username and password

rake db:create

rails server

done