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

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 ffi:
ERROR: Failed to build gem native extension.
rake RUBYARCHDIR=/home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/lib RUBYLIBDIR=/home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/lib
/home/mdemare/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/site_ruby/1.9.1/rubygems.rb:370:in `bin_path': can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)
from /home/mdemare/.rvm/gems/ruby-1.9.2-p136/bin/rake:19:in `<main>'
Gem files will remain installed in /home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6 for inspection.
Results logged to /home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/gen/gem_make.out
I'm getting frequent errors of all kinds while installing gems with native extensions, so I assume that there's something broken with my Ubuntu installation, but I've no idea what. I'll post any information you need to diagnose the problem.
EDIT: When I cd to the ffi gem (mentioned in the second but last line), and run the rake line in line 6, I get "Could not find RubyGem rake-compiler".
After gem i rake-compiler, and run rake again, I get this:
configure: error: source directory already configured; run "make distclean" there first
make: *** [/home/mdemare/.rvm/gems/ruby-1.9.2-p136/gems/ffi-1.0.6/build/x86_64-linux/ffi_c/1.9.2/libffi/.libs/libffi_convenience.a] Error 1
rake aborted!
Command failed with status (2): [make...]
Update:
These are my rake gemspecs:
~ - 10:59>find ~/.rvm/ -name 'rake-0.8.7.gemspec'
~/.rvm/gems/ruby-1.9.2-p136/specifications/rake-0.8.7.gemspec
~/.rvm/gems/ruby-1.9.2-p136#global/specifications/rake-0.8.7.gemspec
~/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/gems/1.9.1/specifications/rake-0.8.7.gemspec
The last one is where gem looks, but that gemspec is different from the first one, and doesn't include the executable. Copying the long one doesn't quite solve the problem though - I get a file not found for the rake executable.

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.

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

#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!

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)

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.

Related

Trying to put bundle in PATH

I'm working on a Ruby project that requires the use of a few gems. I'm a bit confused, since I thought I already had bundler installed on my Mac. I tried installing it just now and got the following error:
Leias-MacBook-Pro:spec leia$ gem install bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
I then tried using --user-install, a trick I picked up from browsing Stack Overflow.
Leias-MacBook-Pro:spec leia$ gem install bundler --user-install
WARNING: You don't have /Users/leia/.gem/ruby/2.3.0/bin in your PATH, gem executables will not run.
Successfully installed bundler-2.0.2
Parsing documentation for bundler-2.0.2
Done installing documentation for bundler after 5 seconds
1 gem installed
Now, I kind of need the gem executables to run, so I opened my .bash_profile and dropped the following code in:
export PATH=/Users/leia/.gem/ruby/2.3.0/bin:$PATH
But no matter how I try to fix it, bundle still won't run. The gem I'm installing is rspec, and I definitely need to be able to run those executables. Am I doing something wrong here? I've tried to follow tutorials and Google similar issues, but I can't figure out what the problem is. Any pointers or suggestions?

why is this sass command giving me an error

I am trying to learn sass so I can develop my front end skills a little bit more because that is what I hope to be some day. The only thing is I can't get sass to work.
Whenever I run the sass --watch . command it returns this error.
>>> Sass is watching for changes. Press Ctrl-C to stop.
write ./test.css
LoadError: no such file to load -- rb-fsevent
Use --trace for backtrace.
I did a bit of research on this error and it was suggested on this site to just simply install the rb-fsevent file that is missing so I ran the gem install rb-fsevent command and then got this error.
Fetching: rb-fsevent-0.9.4.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
so I did a bit of research on THIS error and it was suggested agin on this site to just run the install with sudo. So i did just that I didn't get an error so i was quite excited because I have been fighting with this for a while so i want back to the start of this question and ran the --watch command and got the same exact error. Can anyone help me fix this?
Your first error is because Ruby can't load the rb-fsevent gem. This could be because the gem is not installed. Trying to install the gem was a good idea.
Your second error is because you are trying to install the gem to a directory that you do not have permissions for. Using sudo to do the install is an acceptable solution. You can also do gem install --user-install to install to your home directory.
You are still getting the first error because even though the gem is installed, Ruby cannot load it. This could be because sudo installed the gem with the wrong permissions, or installed it to the wrong location, or Ruby is looking for it in the wrong location.
Thus your solution would be to
Locate the gem files you installed
Check that their permissions allow you to read them
Check ruby -e 'p $LOAD_PATH' to see if Ruby is looking in the right place for the gem

JRuby: Nokogiri 1.6 Failing To Install & Bundler Attempting To Install Already Met Dependency

I am getting an error on jruby (linux) when installing the
"trinidad_diagnostics_extension" gem (though this question is not about trinidad). A chain of dependencies is
generating the error:
"trinidad_diagnostics_extension" depends on "jruby-lint >= 0.3.0"
"jruby-lint >= 0.3.0" in turn depends on "nokogiri >= 1.5.0.beta.4"
Before attempting to install "trinidad_diagnostics_extension", the relevant
part of my gem list looks like this:
$gem list
nokogiri (1.5.9 java)
jruby-lint (0.4.1)
As you can see, the needed dependencies seem already to be met. Nonetheless,
after adding gem 'trinidad_diagnostics_extension' to my Gemfile and then
running jruby -S bundle install, the bundler attempts to install nokogiri
(1.6.0.rc1), and during this installation fails with the following error:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
... bunch of omitted output here
nokogiri.c:42:18: fatal error: util.h: No such file or directory
compilation terminated.
make: *** [nokogiri.o] Error 1
Gem files will remain installed in /home/jg/.rvm/gems/jruby-1.7.3/gems/nokogiri-1.6.0.rc1 for inspection.
Results logged to /home/jg/.rvm/gems/jruby-1.7.3/gems/nokogiri-1.6.0.rc1/ext/nokogiri/gem_make.out
Why is bundler trying to install nokogiri when that dependency is already met?
How can I fix this? Successfully installing nokogiri 1.6 or making the trinidad extension aware that 1.6 does not need to be installed would both be fine solutions.
In case it's relevant I have JRUBY_OPTS=-Xcext.enabled=true
UPDATE
I was able to get it work by first installing the gem outside of bundler:
jruby -S gem install trinidad_diagnostics_extension
And then the bundle command worked fine, since it was already installed. So I got it working by I am still confused by why I had to install it outside of bundler and why that would matter, and would like some insight if anyone has it.
1.6.0.pre1 does not exist for the Java platform, for uninteresting reasons. That said, you should only get prereleases if you specifically ask for them.

How do I get a list of gems that are installed that have native extensions?

I'm on windows, and have updated from ruby 1.8.x to 1.9.x, and am now getting error popups that complain ruby-mssomethingrt.1.8.x.dll is missing.
I would like to find out which gems have native extensions, so I can uninstall them and force a rebuild of the native extensions locally during installation again, to make the error go away.
Based on this answer, here is a solution that finds and offers to reinstall gems with native extensions that works with recent rubies (>=1.9).
native_gems = []
Gem::Specification.each do |spec|
native_gems << "#{spec.name}:#{spec.version}" unless spec.extensions.empty?
end
install_cmd = "gem install #{native_gems.join ' '}"
puts "Found #{native_gems.length} gem(s) with native extensions:"
puts "\n> " + install_cmd, "\nReinstall gems with above command? (yn)"
exec insall_cmd if gets.downcase[0] == 'y'
Example Output:
Found 36 gem(s) with native extensions:
> gem install atomic:1.1.13 bcrypt-ruby:3.0.1 bigdecimal:1.2.0 eventmachine:1.0.3 eventmachine:1.0.0 eventmachine:0.12.10 ffi:1.9.3 ffi:1.9.0 ffi:1.7.0 hiredis:0.4.5 hpricot:0.8.6 io-console:0.4.2 json:1.8.1 json:1.8.0 json:1.7.6 nokogiri:1.6.0 nokogiri:1.5.9 pg:0.17.1 pg:0.17.0 pg:0.16.0 pg:0.15.1 pg:0.13.2 psych:2.0.0 puma:2.7.1 puma:2.6.0 puma:2.4.0 puma:1.6.3 sqlite3:1.3.8 sqlite3:1.3.7 sqlite3:1.3.5 therubyracer:0.12.0 thin:1.5.1 thin:1.5.0 thin:1.4.1 websocket-driver:0.2.3 websocket-driver:0.1.0
Reinstall gems with above command? (yn)
…
A good start would be to look at the gem specification for each gem and see if it has the extensions field set. That should leave you with a short-list of gems to re-install. They don't necessarily all use native extensions, but if you look at the corresponding extconf.rb files, this should be pretty easy to find out.
Update: Here is a short ruby script to list those gems:
require 'rubygems'
Gem.source_index.each do |gem|
spec = Gem.source_index.specification(gem[0])
ext = spec.extensions
puts "#{gem[0]} has extensions: #{ext}" unless ext.empty?
end
You can rebuild (and restore to a pristine state) all installed gems with:
gem pristine --all
--all --no-extensions will restore gems without extensions, but despite being documented, --extensions appears to have no effect (at least on rubygems 1.8.23 on Ubuntu 12.10).
In Cygwin you could try gem list --all -d | grep --before-context=1 --after-context=4 Platform.
gem list
the part after the version next to the gem should indicate whether it's running native code:
e.g. json (1.4.6 x86-mingw32)
The error you are seeing is because one of the gems you are using expects the 1.8 ruby interpreter to be present which it no longer is (as you have upgraded to 1.9).
I would have thought that just running 'gem update' would fix your problem. If it doesn't, then you might need to seek an alternative gem for the one that is expecting the ruby 1.8 interpreter to be present.
Onliner for bundler + rails:
rails r "puts Gem::Specification.select{|i| i.extensions.any?}.map(&:name)"
prints out all native code gems (which usually need updates when updating major Ruby versions)

Rake failing to start

I'm having trouble understanding the following error with Ruby's Rake.
C:\>gem install rake
Successfully installed rake-0.8.7
1 gem installed
Installing ri documentation for rake-0.8.7...
Installing RDoc documentation for rake-0.8.7...
C:\>rake
C:/Ruby192/lib/ruby/1.9.1/rubygems.rb:340:in `bin_path': can't find executable r
ake for rake-0.8.7 (Gem::Exception)
from C:/Ruby192/bin/rake:19:in `<main>'
Running Ruby 1.9.2 for Windows.
Edit: Installing from source yields:
C:\Documents and Settings\XPherior\Desktop\rake-0.8.7\rake-0.8.7>ruby install.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load --
ftools (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from install.rb:3:in `<main>'
The second error, where you have installed into C:\Documenets And Settings\ is occurring because you cannot install ruby into a folder with a space in the path. It should be installed into c:\Ruby\ c:\Ruby#.#.#\ if you want the version # in the path, or something along those lines.
for the first error: there is a bug in the rubyinstaller.org version of ruby 1.9.2, which is causing this by running "gem install rake".
you can read about the error you're getting, here: http://redmine.ruby-lang.org/issues/show/3677
there are a couple of ways to fix this error:
re-install ruby v1.9.2 and don't run "gem install rake". rake v0.8.7 is built into the ruby v1.9.2 installation, so you don't need to re-install it.
if you do want to manually install it, you can delete the ruby.gempspec file from your ruby installation. this file is located at (rubyinstalldir)\lib\ruby\gems\1.9.1\specifications
either of these options will fix the problem for you.
i'm not sure which is "better" off-hand... it may be necessary to delete the gemspec file and reinstall rake, to support updates and new versions in the future. i'm not sure, though. we'll find out once rake is updated and we need to install a new version. or, perhaps, the issue will be fixed in the ruby installation by then, and we'll just need to update our ruby install.
I've run into your both errors.
For the first one. Try the solution post at here http://betterlogic.com/roger/2010/11/ruby-1-9-2-rake-woe/.
And for the second error, it's causes by a library update by the ruby 1.9. From the Programming Ruby 1.9, "ftools have been removed (and replaced by fileutils)." I'm not pretty sure but at least that's an explanation.

Resources