How to install libxml-ruby?

3467 PV

My ruby version is 1.8.7(system version),OS is Ubuntu 12.04.

When I run bundle install,the result was:

Gem files will remain installed in /home/username/.bundler/tmp/4614/gems/libxml-ruby-0.8.3 for inspection.
Results logged to /home/username/.bundler/tmp/4614/gems/libxml-ruby-0.8.3/ext/libxml/gem_make.out

An error occurred while installing libxml-ruby (0.8.3), and Bundler cannot continue.
Make sure that `gem install libxml-ruby -v '0.8.3'` succeeds before bundling.

When I run sudo gem install libxml-ruby -v '0.8.3',the result was:

Building native extensions.  This could take a while...
ERROR:  Error installing libxml-ruby:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
extconf.rb:6: stack level too deep (SystemStackError)

Gem files will remain installed in /var/lib/gems/1.9.1/gems/libxml-ruby-0.8.3 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/libxml-ruby-0.8.3/ext/libxml/gem_make.out

How to install libxml-ruby?


There are several reasons for that.

The version of ruby that pointed from gem.

The first reason, ruby and gem version problem.

My ruby version is 1.8.7

Perhaps you checked your ruby version with the command ruby -v or something like that . However your error log tells us gem targeted ruby 1.9.1.

    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb

To display target version, do following command

$ gem env

this will show result like below

RubyGems Environment:
  - RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]

# snip

if RUBY VERSION is not 1.8.7, you need change the gem version using sudo update-alternatives --config gem or install older versions gem and install that to update-alternatives.

note: You can check the versions following command

$ update-alternatives --list gem

How to install older version

If you don't have older versions gem, you can install with following steps:

$ cd /tmp
$ wget 
$ tar xvfz rubygems-1.8.17.tgz
$ cd rubygems-1.8.17/
$ ruby setup.rb         # I think this ruby must be  '1.8' version's ruby, 
                        # or gem will target unexpected version.

How to append older gem to update-alternatives

To make version switchable gem with update-alternatives, do like below:

$ sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem.1.8 50

NOTE: 50 is priority. you can change this value as you like.

list all gem, installed to update-alternatives.

$ update-alternatives --list gem

you can also list installed ruby.

$ update-alternatives --list ruby

how to switch.

$ sudo update-alternatives --config gem
There are 2 choices for the alternative gem (providing /usr/bin/gem).

  Selection    Path               Priority   Status
* 0            /usr/bin/gem1.8     50        auto mode
  1            /usr/bin/gem1.8     50        manual mode
  2            /usr/bin/gem1.9.1   10        manual mode

Press enter to keep the current choice[*], or type selection number:  1

check version, and target

$ sudo gem -v
$ sudo gem env
RubyGems Environment:
  - RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
  - INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8


Need to install required packages.

The second reason, libxml-ruby require some packages. you need install these if not yet.

maybe libm was already installed.
( you can find under /usr/lib/x86_64-linux-gnu/ directory. )

$ sudo apt-get install libz-dev
$ sudo apt-get install libiconv-ruby
$ sudo apt-get install libxml2-dev

Also need to install some dev packages.

When install libxml-ruby, gem build native modules.
That required some library like gcc, make, g++, ruby-dev.

I use Ubuntu 12.04 server (that is not installed even ruby) to write this answer.

I hope this will help you.

編集 履歴 (4)
  • Thank you very much.I have follow your manual to install the necessary libraries.But I have no luck,the result was the same.I used `rvm use system` to change my ruby version.And... -
  • If I run `rvm use 1.8.7`,it showed to me `Warning! Executable 'gem' missing, something went wrong with this ruby installation!`By the way... -
  • I think `sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem.1.8 50` should be `sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 50`. -
  • Thanks, yes indeed. `gem1.8` is correct.
    about rvm error , I will report if I find a way of solving.