Search code examples
ruby-on-railsbundlerrbenv

How to resolve gem dependencies when installing rbenv?


Recently I have installed rbenv and specified ruby to 2.3.1 and rails to 5.1.1 but I couldn't run my projects because I got:

Ignoring json-2.1.0 because its extensions are not built.  Try: gem pristine json --version 2.1.0
Ignoring nokogiri-1.8.1 because its extensions are not built.  Try: gem pristine nokogiri --version 1.8.1
Ignoring unf_ext-0.0.7.4 because its extensions are not built.  Try: gem pristine unf_ext --version 0.0.7.4
Ignoring yajl-ruby-1.3.1 because its extensions are not built.  Try: gem pristine yajl-ruby --version 1.3.1
/var/lib/gems/2.3.0/gems/bundler-1.16.1/lib/bundler/spec_set.rb:88:in `block in materialize': Could not find unf_ext-0.0.7.4 in any of the sources (Bundler::GemNotFound)

from /var/lib/gems/2.3.0/gems/bundler-1.16.1/lib/bundler/spec_set.rb:82:in `map!'
...
from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/spring-2.0.2/bin/spring:49:in `<main>'

I ran:

bundle install

Installation passed successfully, but... Now I get:

/home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/lib/ffi.rb:6:in `require': incompatible library version - /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/lib/ffi_c.so (LoadError)
    from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/lib/ffi.rb:6:in `rescue in <top (required)>'
    from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/ffi-1.9.18/lib/ffi.rb:3:in `<top (required)>'
    from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/rb-inotify-0.9.8/lib/rb-inotify/native.rb:1:in `require'
    from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/rb-inotify-0.9.8/lib/rb-inotify/native.rb:1:in `<top (required)>'
    from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/rb-inotify-0.9.8/lib/rb-inotify.rb:1:in `require'
    from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/rb-inotify-0.9.8/lib/rb-inotify.rb:1:in `<top (required)>'
    from /home/alex/pnv/vendor/bundle/ruby/2.3.0/gems/listen-3.0.8/lib
    ...
    from /home/alex/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:59:in `require'
    from -e:1:in `<main>'

And I have no idea how to resolve this. Any help is appreciated!

UPDATE 1: Finally, I've found source of the evil bug - nevertheless, I specify Rails 5.1.1, when I run rails new app_name, it installs 5.1.6! And seems like it uses 5.1.6 gem dependencies... Still don't know how to resolve instead of upgrading to >= 5.1.6


Solution

  • Add the following line to your Gemfile.

    gem 'rails', '5.1.1'

    Run bundle install