Saturday, October 31, 2015

Installing Rails 4 on Ubuntu 14.04

I am writing this because I [often] have to set up rails on Ubuntu, run into some small glitches, fix them with some help from here and there, and forget those problems and re-do the whole fixing over and over. This time I decided to write down the full steps because I want to help others who want the same thing.

The whole steps below are take from goRails.com, specifically in the way/order I follow to avoid any issues.

Follow this steps if you are on
Ubuntu 14.04 64bit (14.04.3, this probably doesn't matter)
and want to install
Ruby 2.2.3 using RVM,
Rails 4.2.4 and
MySQL

1. Install Ruby using RVM (I like to use rvm)
Install ruby dependencies:

 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 libcurl4-openssl-dev python-software-properties libffi-dev  

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

Now there are two things here: Running the next step [below] given at goRails gives you a signature verification failure, which is not a problem, so don't worry. Read on before executing this next step:
 curl -L https://get.rvm.io | bash -s stable  

The above code throws the mentioned failure as follows:

"gpg: Can't check signature: public key not found
Warning, RVM 1.26.0 introduces signed releases and automated check of signatures when GPG software found.
Assuming you trust Michal Papis import the mpapis public key (downloading the signatures).

GPG signature verification failed for '/home/masseu/.rvm/archives/rvm-1.26.11.tgz' - 'https://github.com/rvm/rvm/releases/download/1.26.11/1.26.11.tar.gz.asc'!
try downloading the signatures:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

or if it fails:

command curl -sSL https://rvm.io/mpapis.asc | gpg --import -"


To fix this simply run the suggested command to download the signature:
 gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3  

And then rerun the previous curl command. You might want to first run the above command to download the signature and then run the curl command to avoid the whole fuss there. That's why I said read on.

1.2 Now install Ruby 2.2.3
 source ~/.rvm/scripts/rvm  
 rvm install 2.2.3 --disable-binary  
 rvm use 2.2.3 --default  
 ruby -v  

Why ---disable-binary ? Well, this was a fix to one error i ran into that has got to do with nokogiri gem during the installation of Rails.

Thanks to Joshua Rumbut's comment on goRails: "Using Ubuntu 14.04 (Trusty) and RVM I needed install ruby with

rvm install 2.2.3 --disable-binary #or if you already did install: rvm reinstall 2.2.3 --disable-binary

in order to have the development headers available for nokogiri et al. "


2. Install Rails 4.2.4
Quote on quote from goRails:
"Since Rails ships with so many dependencies these days, we're going to need to install a Javascript runtime like NodeJS. This lets you use Coffeescript and the Asset Pipeline in Rails which combines and minifies your javascript to provide a faster production environment."

Install NodeJS and Rails
 sudo add-apt-repository ppa:chris-lea/node.js  
 sudo apt-get update  
 sudo apt-get install nodejs  
 gem install rails -v 4.2.4  

3. Install mySQL
 sudo apt-get install mysql-server mysql-client libmysqlclient-dev  


That's it. Oh wait, another helpful comment from Diego Cassol on goRails:

"Great job! I appreciate your help! TY so much! But, i have one information that can be necessary and important to someone.

The version of my ubuntu is 14.04, and the current version of the mysql2 is installed with the last version (stable) ruby.

If
you have a problem similar as: " Gem::LoadError Specified 'mysql2' for
database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your
Gemfile", and your server not work, the solution can be a following:

Open
your folder that contain your project, and find your Gemfile. In the
gemfile, add the version of the mysql2 '~> 0.3.20' . For example:

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use mysql as the database for Active Records
gem 'mysql2', '~> 0.3.20'

After these steps, you can be continue your setup normally.

Regards!

Diego Cassol."


I hope your set up went smoothly.

2 comments: