Error installing gems that use native extensions on Ubuntu, Ruby 1.9.2 via RVM

前端 未结 5 1708

I get an error while trying to install the ffi gem:

~ - 16:54>gem i ffi
Building native extensions.  This could take a while...
ERROR:  Error installing f         


        
相关标签:
5条回答
  • 2020-12-25 09:23

    I had a similar problem, and a workaround at http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=529663 helped me. In short, try to install the gem with: $ rake=/usr/bin/rake gem install ffi

    0 讨论(0)
  • 2020-12-25 09:24

    This caused me a ton of aggravation at the Boston Hack Day when trying to install Vagrant (for which FFI is a dependency). I ended up wasting so much time that I switched machines to work around the problem.

    After the fact, I found a hack that works (although I'm sure there's a better solution). The file that the error message is complaining about

    ~/.rvm/gems/ruby-1.9.2-p180/bin/rake
    

    differs from other similar copies in that it's missing path setup stuff at the head, so I copied these lines from one of the files that had them:

    [genericized per @danv's answer below. Thanks for the improvement!]

    ENV['GEM_HOME']=ENV['GEM_HOME'] || '~/.rvm/gems/ruby-1.9.2-p180'
    ENV['GEM_PATH']=ENV['GEM_PATH'] || '~/.rvm/gems/ruby-1.9.2-p180:~/.rvm/gems/ruby-1.9.2-p180@global'
    ENV['PATH']='~/.rvm/gems/ruby-1.9.2-p180/bin:~/.rvm/gems/ruby-1.9.2-p180@global/bin:~/.rvm/rubies/ruby-1.9.2-p180/bin:' + ENV['PATH']
    

    That fixed it for me. This was a new Ubuntu 10.10 install with no default Ruby installation (which could be part of the problem) and Ruby 1.9.2 installed using RVM. Lots of other gems installed fine, including those requiring native compilation, so the problem is something specific to FFI.

    0 讨论(0)
  • 2020-12-25 09:31

    @Tom Morris - Tried your method and it worked fine.

    I inserted your path specs (modified - see below) into ~/.rvm/gems/ruby-1.9.2-p180/bin/rake after line 12.

    I modified the path specs so they are generic using ~ for the user home:

    ENV['GEM_HOME']=ENV['GEM_HOME'] || "~/.rvm/gems/ruby-1.9.2-p180"
    ENV['GEM_PATH']=ENV['GEM_PATH'] || "~/.rvm/gems/ruby-1.9.2-p180:~/.rvm/gems/ruby-1.9.2-p180@global"
    ENV['PATH']="~/.rvm/gems/ruby-1.9.2-p180/bin:~/.rvm/gems/ruby-1.9.2-p180@global/bin:~/.rvm/rubies/ruby-1.9.2-p180/bin:"+ ENV['PATH']
    

    Thanks for finding this fix!

    0 讨论(0)
  • 2020-12-25 09:35

    The installer attempts to run rake but fails when it isn't found:

    can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)
    

    You need to install the rake gem: gem install rake.

    0 讨论(0)
  • 2020-12-25 09:40

    Thanks @Tim Morris and @danv, your answers / comments helped. I adjusted for my setup, which is based more towards a superuser environment. Now this is what /usr/local/rvm/gems/ruby-1.9.2-p180/bin/rake looks like on my server:

    require 'rubygems'
    
    version = ">= 0"
    ENV['GEM_HOME']=ENV['GEM_HOME'] || "/usr/local/rvm/gems/ruby-1.9.2-p180"
    ENV['GEM_PATH']=ENV['GEM_PATH'] || "/usr/local/rvm/gems/ruby-1.9.2-p180:/usr/local/rvm/gems/ruby-1.9.2-p180@global"
    
    if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
      version = $1
      ARGV.shift
    end
    
    gem 'rake', version
    load Gem.bin_path('rake', 'rake', version)
    
    0 讨论(0)
提交回复
热议问题