Technical miscellanea by Derrick Coetzee

Installing Ruby 1.9.2 and gems on Ubuntu 11.10

By default, the “ruby” package on Ubuntu 11.10 (Oneiric) refers to an older version of Ruby, 1.8.7 – probably for compatibility reasons. To use the newest version of Ruby and Gem, do:

  • sudo apt-get install ruby1.9.1
  • update-alternatives --config ruby
  • (select the option reading “/usr/bin/ruby1.9.1″)
  • update-alternatives --config gem
  • (select the option reading “/usr/bin/gem1.9.1″)

Contrary to their names, /usr/bin/ruby1.9.1 is actually a newer version (1.9.2p290 at the present time) and /usr/bin/gem1.9.1 is actually RubyGems 1.3.7 (there is no RubyGems 1.9.1). These numbers refer to the package name ruby1.9.1.

During a “bundle install”, depending on what gems are being installed, you may encounter other errors. I encountered the following three:

  • ERROR: Error installing nokogiri:
    ERROR: Failed to build gem native extension.
    
    /usr/bin/ruby1.9.1 extconf.rb
    <internal:lib/rubygems/custom_require>:29:in `require': no such file or load -- mkmf (LoadError)
    from <internal:lib/rubygems/custom_require>:29:in `require`
    from extconf.rb:5:in `<main>'

    To fix this one do: apt-get install ruby1.9.1-dev

    ERROR: Error installing nokogiri:
    ERROR: Failed to build gem native extension.
    
    /usr/bin/ruby1.9.1 extconf.rb
    checking for libxml/parser.h... no
    -----
    libxml2 is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
    -----

    To fix this one do: apt-get install libxml2-dev

    ERROR: Error installing nokogiri:
    ERROR: Failed to build gem native extension.
    
    /usr/bin/ruby1.9.1 extconf.rb
    checking for libxml/parser.h... yes
    checking for libxslt/xslt.h... no
    -----
    libxslt is missing.  please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
    -----

    To fix this one do: apt-get install libxslt1-dev

  • Installing sqlite3 (1.3.4) with native extensions
    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
    /usr/bin/ruby1.8 extconf.rb
    checking for sqlite3.h... no
    sqlite3.h is missing. Try 'port install sqlite3 + universal'
    or 'yum install sqlite3-devel' and check your shared library search path (the
    location where your sqlite3 shared library is located).

    To fix this one do: sudo apt-get install libsqlite3-dev

  • Gem::InstallError: hoe requires RubyGems version >= 1.4. Try 'gem update --system' to update RubyGems itself.

    Version 1.9.2 of the “hoe” gem requires a newer version of RubyGems than is presently available via the Ubuntu package manager. You have to force an upgrade with:

    sudo REALLY_GEM_UPDATE_SYSTEM=1 gem update --system

    After doing so, you must redo “gem install bundler” and “bundle install”. Note that this might screw up other things, since you’re upgrading gem outside the package manager interface now.

If these instructions don’t work for you, or you encounter problems with other gems and figure out how to fix them, please post in the comments below!

8 Comments to Installing Ruby 1.9.2 and gems on Ubuntu 11.10

  1. Paulo's Gravatar Paulo
    2012-03-08 at 4:42 am | Permalink

    It worked!
    Thank you.. you saved my life! :)

    Output:
    paulo@Vaio-Linux ~ $ sudo gem install nokogiri
    Building native extensions. This could take a while…
    Successfully installed nokogiri-1.5.0
    1 gem installed
    Installing ri documentation for nokogiri-1.5.0…
    Installing RDoc documentation for nokogiri-1.5.0…

  2. Simeon's Gravatar Simeon
    2012-04-03 at 2:28 pm | Permalink

    I am receiving the following error when doing the bundle install:
    ###
    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

    /usr/bin/ruby1.8 extconf.rb
    extconf.rb:1:in `require’: no such file to load — mkmf (LoadError)
    from extconf.rb:1

    Gem files will remain installed in /root/snorby/vendor/cache/ruby/1.8/gems/RedCloth-4.2.9 for inspection.
    Results logged to /root/snorby/vendor/cache/ruby/1.8/gems/RedCloth-4.2.9/ext/redcloth_scan/gem_make.out
    An error occured while installing RedCloth (4.2.9), and Bundler cannot continue.
    Make sure that `gem install RedCloth -v ’4.2.9′` succeeds before bundling.

    ####

    Not sure what I can do to fix this…this is all in relation to installing snorby. Any suggestions?

  3. Pathsniffer's Gravatar Pathsniffer
    2012-04-04 at 9:43 pm | Permalink

    Thank you!

  4. simon's Gravatar simon
    2012-05-11 at 5:09 pm | Permalink

    thanks man

  5. Anonymous's Gravatar Anonymous
    2012-05-29 at 5:03 pm | Permalink

    You’re awesome. This was incredibly helpful.

  6. 2012-08-24 at 12:16 pm | Permalink

    apt-get install imagemagick -y –force-yes
    apt-get install git -y –force-yes
    apt-get install ruby1.9.1 ruby1.9.1-dev -y –force-yes
    apt-get install libxml2-dev -y –force-yes
    apt-get install libxslt1-dev -y –force-yes
    apt-get install libsqlite3-dev -y –force-yes
    apt-get install libmysql++-dev -y –force-yes

  7. guti6's Gravatar guti6
    2012-09-02 at 2:30 pm | Permalink

    thank you so much

  8. 2012-11-30 at 12:59 pm | Permalink

    thank you, I fixed the problems with nokogiri in 10sec

  1. By on 2012-03-03 at 3:36 pm

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>