Search code examples
rubyrvmbundler

bundle install using wrong ruby with rvm when building native extension?


I'm using bundle install to install rest-client. It's failing with the following:

$ bundle
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Resolving dependencies...
Installing unf_ext 0.0.7.4 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /home/roger/.rvm/gems/ruby-2.3.4@junk-drawer/gems/unf_ext-0.0.7.4/ext/unf_ext
/usr/bin/ruby2.3 -r ./siteconf20180115-9722-1iow75n.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /home/roger/.rvm/gems/ruby-2.3.4@junk-drawer/gems/unf_ext-0.0.7.4 for inspection.
Results logged to /home/roger/.rvm/gems/ruby-2.3.4@junk-drawer/extensions/x86_64-linux/2.3.0/unf_ext-0.0.7.4/gem_make.out
Installing mime-types-data 3.2016.0521
Installing netrc 0.11.0
Using bundler 1.11.2
An error occurred while installing unf_ext (0.0.7.4), and Bundler cannot continue.
Make sure that `gem install unf_ext -v '0.0.7.4'` succeeds before bundling.

I'm using rvm, which appears to be working correctly, if I'm reading the output from rvm info right.

which ruby reports /home/roger/.rvm/rubies/ruby-2.3.4/bin/ruby, which looks right.

I found Install ruby headers with rvm, but I have Ruby headers in (apparently) the correct place:

$ ruby -rmkmf -e 'print RbConfig::CONFIG["rubyhdrdir"]'
/home/roger/.rvm/rubies/ruby-2.3.4/include/ruby-2.3.0
$ ls /home/roger/.rvm/rubies/ruby-2.3.4/include/ruby-2.3.0
ruby/  ruby.h  x86_64-linux/

In the output from bundle, I see /usr/bin/ruby2.3, which looks suspicious.

It's looking in the wrong place for Ruby header files. How do I get it to use the RVM-installed ones?


Solution

  • I was using the wrong bundle.

    $ which bundle
    /usr/bin/bundle
    

    Either the one included in Ubuntu 16.04 is old, or using the system-installed bundler doesn't work with rvm-installed Ruby.

    $ gem install bundler
    Fetching: bundler-1.16.1.gem (100%)
    ...
    1 gem installed
    $ which bundle
    /home/roger/.rvm/gems/ruby-2.3.4@junk-drawer/bin/bundle
    

    That looks better.

    $ bundle
    Fetching gem metadata from https://rubygems.org/.........
    Resolving dependencies...
    Using bundler 1.16.1
    ...
    Bundle complete! 1 Gemfile dependency, 9 gems now installed.
    Use `bundle info [gemname]` to see where a bundled gem is installed.
    

    Lesson learned: when using rvm, remember to gem install bundler as well.