In this posts some notes on installing Ruby and RubyGems on Bluehost, my hosting provider. While I was writing this I also tried it on Solaris 11 and Ubuntu 12.10 as a regular (non-root) user. So now I can deploy the latest version of Ruby to most places I push code to.

Of course this only makes sense if you want to have the latest version or if Ruby is not installed at all and you have no sudo / root rights. For Ubuntu I usually have full access so running an "$ apt-get install ruby" would be all it takes. For Bluehost I obviously don't have root access, for Solaris usually the same. Bluehost does come with gem 1.7.2 and ruby 1.8.7 out of the box. Learning Ruby I want to make sure though I can use the latest version on my local- and remote hosts, hence this post.

Installation steps

  • First get the latest version:
  • $ mkdir ~/ruby && cd ~/ruby
    $ wget
    (at this time)
    $ bzcat ruby-1.9.3-p286.tar.bz2 | tar -xvf -
    $ cd ruby-1.9.3-p286

  • Install it (see also this article).
  • $ ./configure --prefix=$HOME
    $ make
    $ make install

    !! On Solaris 11 you might need to install gcc ($ sudo pkg install gcc-3) first.

    !! Although this worked perfectly as a user on Ubuntu and Solaris, on Bluehost this failed. On a hosting box it might be better to run the following commands which I found here:

    (still in ruby-1.9.3-p286)
    $ autoconf
    $ nice ./configure --enable-shared --prefix=$HOME/ruby/ 
    $ nice make 
    $ make install

    featured image ruby rubygems install

  • Next make sure you update your $PATH variable in your shell's dotfile with the new Ruby binary (in my case .bashrc).
  • If this is your first Ruby installation you can just append it to the end, if you have multiple instances, like I had on Bluehost, you might prepend it so that the shell looks first at the Ruby binary you installed with your user account. For dealing with multiple Ruby versions on your box, you might want to check out Ruby Version Manager as well.

    $ vi ~/.bashrc
    export PATH=$HOME/ruby/bin:$PATH

    If you don't want to mess with the PATH variable, you can also create aliases:

    $ vi ~/.bashrc
    alias ruby19='$HOME/ruby/bin/ruby'
    alias gem18='$HOME/ruby/bin/gem'
  • Next install RubyGems
  • $ wget
    (at this time)
    $ zcat rubygems-1.8.24.tgz | tar -xvf -
    (gzcat on Solaris)
    $ cd rubygems-1.8.24
    $ ruby setup.rb 
    (where ruby is $home/ruby/bin/ruby due to the PATH change in the previous step)

    <my home>/bin/ruby/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
    It seems your ruby installation is missing psych (for YAML output).
    To eliminate this warning, please install libyaml and reinstall your ruby.
    RubyGems 1.8.24 installed
    == 1.8.24 / 2012-04-27
    * 1 bug fix:
      * Install the .pem files properly. Fixes #320
      * Remove OpenSSL dependency from the http code path
    RubyGems installed the following executables:
      <my home>/ruby/bin/gem

    The libyaml error didn't get in the way so far, but usually it is better to solve any errors ... I got this error on each Unix flavor (as a user).

  • Bluehost recommends the following GEM variable settings, again in your shell's dotfile:
  • export GEM_HOME=$HOME/ruby/gems
    export GEM_PATH=$GEM_HOME:/usr/lib/ruby/gems/1.8
    export GEM_CACHE=$GEM_HOME/cache
    (and if you will use rails)
    ENV['GEM_PATH'] = '/path/to/your/home/ruby/gems:/usr/lib/ruby/gems/1.8'

    /usr/lib/ruby/gems/1.8 is the default gems location, if this is the first installation just leave this off.

  • To test if it works I install two gems:
  • $ gem install RedCloth
    $ gem install hpricot
    $ gem list --local
    *** LOCAL GEMS ***
    hpricot (0.8.6)
    RedCloth (4.2.9)
    $ ls $HOME/ruby/gems/gems
    hpricot-0.8.6  RedCloth-4.2.9

    !! Note that on Ubuntu you might get the following error which means you have to install zlib ($ sudo apt-get install zlib1g-dev) :

    ERROR:  Loading command: install (LoadError)
        cannot load such file -- zlib
  • Testing the new gem:
  • $ irb
    irb(main):001:0> require "rubygems"
    => true
    irb(main):002:0> require "RedCloth"
    => true
    irb(main):003:0> r ="this is a *test* of _using RedCloth_")
    => "this is a *test* of _using RedCloth_"
    irb(main):004:0> puts r.to_html
    <p>this is a <strong>test</strong> of <em>using RedCloth</em></p>
    => nil


And that's it. Now I can write Ruby 1.9.x scripts knowing that they will work on my remote servers because I will simply install the latest Ruby version as my user.

Bob Belderbos

Software Developer, Pythonista, Data Geek, Student of Life. About me