Wednesday, December 23, 2015

Step by step to install Ruby on Ubuntu 14.04 to prep for Rails

I am using the gorails.com website for most of the information but if you follow that guide, you'll undoubtedly run into errors.  I'm mostly documenting this for personal use but feel free to reference.

Here are the details to my environment...

  • Laptop/Desktop with enough ram to run virtual machines on Oracle VirtualBox.  
    • I normally give each machine 2GB of RAM and about 30GB of hard drive space.
  • Fresh install of XUbuntu or plain Jane Ubuntu 14.04

These notes are if you will be installing Ruby 2.2.4.  I'm only going up to the part on the gorails.com site where it installs Ruby before you get to the Git section. The last step on this post should get you past the errors I encountered while installing Rails.

Setup/prepwork...
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

Before performing this next step, click on the Edit menu option of your Terminal window. Click on Profile Preferences --> Title and Command tab --> Put a check mark in Run command as a login shell.  In XUbuntu it's Edit --> Preferences --> Put a check mark in Run command as login shell within the General tab.

Not on the gorails.com guide...
command curl -ssl https://rvm.io/mpapis.asc | gpg --import

Setup for RVM...
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm

I ran across a forum post to run this command or you could close your terminal window and re-open it...
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
Update RVM...


rvm requirements

RVM install...
rvm install 2.3.1
rvm use 2.3.1 --default
ruby -v

This tells Rubygems not to install documentation locally and then installs the bundler...
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler
At this point, you can navigate over to the gorails.com webpage to finish your install if you plan on installing Rails. Good luck!

Ubuntu 15.10 and Rails (unable to install nodejs)

The guide I'm following gives this command as one of the steps to install Rails...

sudo add-apt-repository ppa:chris-lea/node.js
When typing that out in version 15.10, I got an error.

I read two forum posts suggesting to use 14.04 because 15.10 wasn't supported.

Rails install on XUbuntu 14.04 (ERROR: Failed to build gem native extension)

I am following the steps on this page verbatim but came across an error when I got to the point of installing Rails.  This is the error I got...

Fetching: nokogiri-1.6.7.1.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
 ERROR: Failed to build gem native extension.

    /home/user/.rvm/rubies/ruby-2.2.4/bin/ruby -r ./siteconf20151223-26597-j3i7to.rb extconf.rb
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
 --with-opt-dir
 --without-opt-dir
 --with-opt-include
 --without-opt-include=${opt-dir}/include
 --with-opt-lib
 --without-opt-lib=${opt-dir}/lib
 --with-make-prog
 --without-make-prog
 --srcdir=.
 --curdir
 --ruby=/home/user/.rvm/rubies/ruby-2.2.4/bin/$(RUBY_BASE_NAME)
 --help
 --clean
/home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
 from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `block in try_compile'
 from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:522:in `with_werror'
 from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `try_compile'
 from extconf.rb:80:in `nokogiri_try_compile'
 from extconf.rb:87:in `block in add_cflags'
 from /home/user/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:619:in `with_cflags'
 from extconf.rb:86:in `add_cflags'
 from extconf.rb:336:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /home/user/.rvm/gems/ruby-2.2.4/gems/nokogiri-1.6.7.1 for inspection.
Results logged to /home/user/.rvm/gems/ruby-2.2.4/extensions/x86_64-linux/2.2.0/nokogiri-1.6.7.1/gem_make.out
I read many forum posts where I tried a handful of suggestions and none of them worked. I finally came across a stack overflow post where the suggestion of running this command was towards the bottom...


sudo apt-get install libgmp-dev
...or...
sudo apt-get install libgmp3-dev
Many of the suggestions I found on a few different forum posts stated that I needed to run...
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
...but given the setup guide I'm following (along with a few notes I've take), I'd already installed all of those packages.  The extra package needs to be installed for XUbuntu 14.04 and the regular Ubuntu 14.04 images in order to install Rails.

Installing Ruby onto XUbuntu 14.04 (kept installing source)

Trying to install ROR on an XUbuntu 14.04 VirtualBox vm.  Thought I'd mention one of the problems I ran into.  At first I was trying to install RVM/ROR etc from this page on an xubuntu-14.04.3-desktop-i386 image and every time I got to the part of running this line...

rvm install 2.2.3
...the install would download the source and then have to compile.  After some troubleshooting and reading some forum posts, I found out that the binaries weren't available. I did that by typing...

rvm list remote
...and only 2 JRuby binaries were showing up.  When I typed in...

rvm info
...I then noticed I was in a 32 bit environment and not a 64 bit environment like my other Ubuntu image.  After downloading and installing the 64 bit image (xubuntu-14.04.3-desktop-amd64.iso), I no longer had this issue.