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.


Tuesday, January 6, 2015

My RoR install

I've discovered and decided to follow through with the free online tutorial/class on the Odin Projects website.  Because I'm trying to become a full stack Ruby developer, I figured it would be good material to read and try to absorb.

I'm currently on the Web Development 101 >> The Basics >> Project Installations section where it's instructing all those following along to decide on an environment.  Yes, I did go ahead and sign up for a free account on the Nitrous website just to check it out. If you click the link on the Odin Project website that takes you to the Nitrous website, you do get a free account.  Going directly to the Nitrous website won't allow you to setup a free account.

Even though I setup an account on Nitrous, if I am going to want to plant myself into a development position, I need to get as familiar with the Linux platform as best as I can so I'm following along with the Linux environment setup. The Odin Project points it's followers to the RailsBridge Installfest webpage to setup an environment. If you get errors setting up your environment, they strongly encourage you to go through Nitrous.

I went ahead and followed the directions found on RailsBridge but ran into an error trying to install RVM. They also don't mention anything about modifying your bashrc file. In the past, I've also followed the setup instructions on the GoRails website. I'm going to list below the steps I took to get my environment setup but will give the readers digest version. If you want more of an explanation on these steps, please click on the appropriate link above.


I use Windows because that is what I'm most familiar as well as that is the platform that we must use where I work. So I use virtual machines with Linux installed.  My current choice of Linux flavor is Ubuntu. I created a brand new machine with version 14.04. I installed SPE (for when I do get back to learning Python).  I was using Scite but then I tried Geany out one day and fell in love with it because of the option to have a terminal window within one program and I don't have to switch back and forth when I want to try something out in IRB.  To each their own on which editor you choose.

From the point of having Ubuntu installed and updated along with having an editor ready to go, I performed the following steps in the terminal...

sudo apt-get install autoconf automake bison build-essential curl git-core 
libapr1 libaprutil1 libc6-dev libltdl-dev libreadline6 libreadline6-dev 
libsqlite3-0 libsqlite3-dev libssl-dev libtool libxml2-dev libxslt-dev 
libxslt1-dev libyaml-dev ncurses-dev nodejs openssl sqlite3 zlib1g
zlib1g-dev
 
Note: Do not copy and paste the above into your terminal window. Type it all out. 

If you are running Ubuntu 12.04 or 14.04, click on the Edit option on your terminal window, choose the Profile Preferences option, select the Title and Command tab and finally make sure there is a check mark next to the Run command as a login shell box. Click on the close button and then restart your terminal session.

Now to install RVM (assuming you don't want to use rbenv).  Instructions I've read from a few websites state to run this line...

curl -L get.rvm.io | bash -s stable

...I get a "GPG signature verification failed..." message when I try and download rvm.  A few lines below that error message it tells me to run...

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

If that fails, you can run the following...

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

The line on your screen may be different. After obtaining the key, I'm now able to run the curl line above.

When I try and run...

type rvm | head -1

...I get "-bash: type: rvm: not found".  When I close the terminal again and restart it and run the above command, I get...

rvm is a function

...which is a good thing. Next, enter the following two lines to update your environment and to make the appropriate change to your bashrc profile...

source ~/.rvm/scripts/rvm
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc


Next install RVM with the following...

rvm install 2.2

This process took 5 minutes on my machine. On the last line you see after the above process completes is "Ruby was built without documentation, to build it run: rvm docs generate-ri".  I personally like to have my documentation local so I went ahead and ran...

rvm docs generate-ri

This process took 1-2 minutes. Next, type in the following two commands...

rvm use 2.2
rvm --default use 2.2

To test your installation, type the following...

ruby -v

Last but not least, install rails with the following...

gem install rails

That's all I will cover for this entry. I'm still new to all of this but I've read a lot of blogs and documentation on the install. If I've messed something up, by all means, please comment.