6

I'm trying to work on a vagrant / chef project in eclipse. I'm fairly new to both technologies and a little rusty with ruby. I've installed rdt and have a ruby project with the code in.

However, eclipse doesn't seem to understand that gems are required. Is there a way to get ruby gems and eclipse to play nicely together. I thought that I could add gems as libraries but that doesn't seem to work.

Jeremy French
  • 11,707
  • 6
  • 46
  • 71

4 Answers4

2

I was having a very similar problem of getting Eclipse to recognize my installed gems. I was using rvm, with the default pointing to ruby 2.1.0. The ruby code that I was debugging had a single require 'mail' at the top. When running or debugging the script, the console displayed an error:

/Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- mail (LoadError)
     from /Users/username/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
`<main>'

Eclipse had the correct ruby configured in its Preferences > Ruby > Interpreters: /Users/username/.rvm/rubies/ruby-2.1.0/bin/ruby

I knew the mail gem was installed for that ruby, outside of Eclipse:

$ gem which mail
/Users/username/.rvm/gems/ruby-2.1.0/gems/mail-2.6.3/lib/mail.rb

I tried @Don Kirkby's suggestion of adding -rubygems as an Interpreter argument in Debug Configurations, but it still wasn't working.

What DID get it working, oddly enough, was to add the GEM_HOME and GEM_PATH variables to the Environment section of the Debug Configurations.

I found the correct values (set by rvm, I presume) by echoing them in the terminal, outside of Eclipse:

$ echo $GEM_HOME
/Users/username/.rvm/gems/ruby-2.1.0
$ echo $GEM_PATH
/Users/username/.rvm/gems/ruby-2.1.0:/Users/username/.rvm/gems/ruby-2.1.0@global

Adding those two as environment variables in Debug Configurations > Environment tab did get debugging working in Eclipse, using the Ruby Built-In Debugger as the debug Engine in Preferences. Incidentally, I tried using 'Fast Ruby Debugger (ruby-debug)' engine, but got this error:

dyld: lazy symbol binding failed: Symbol not found: _rb_vm_get_sourceline
  Referenced from: /Users/username/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/debugger-1.6.8/ruby_debug.bundle
  Expected in: flat namespace

dyld: Symbol not found: _rb_vm_get_sourceline
  Referenced from: /Users/username/.rvm/gems/ruby-2.1.0/extensions/x86_64-darwin-12/2.1.0-static/debugger-1.6.8/ruby_debug.bundle
  Expected in: flat namespace

Sidenote: Trying to hunt down a fix to the Symbol not found error for the Fast Ruby Debugger engine led me to this thread: Debugging in ruby 1.9 , which seems to imply that neither ruby-debug nor debugger gem is appropriate to use with ruby 2.0+, and instead recommended the byebug gem. But since I don't see a way to use byebug with Eclipse, I just ended up using the Ruby Built-In Debugger engine with the debugger and ruby-debug-ide gems:

$ gem install debugger
Successfully installed debugger-1.6.8
$ gem install ruby-debug-ide
Successfully installed ruby-debug-ide-0.4.26

which I got from this post: https://endocode.com/blog/2012/09/03/debugging-ruby-1-9-3-applications-in-eclipse/

Hopefully this is helpful to somebody who's trying to get Ruby 1.9/2.0+ debugging working with Eclipse.

Dmitri Zagidulin
  • 1,117
  • 9
  • 23
0

Try to use rvm (https://rvm.io/) and gemsets to manage the ruby and gems needed for this project. There is already a stackoverflower answer here: https://stackoverflow.com/a/6574260 that covers getting your eclipse project to recognize rvm settings via a .rvmrc file.

Community
  • 1
  • 1
bikeonastick
  • 769
  • 1
  • 5
  • 5
0

From Eclipse's Window menu, choose Preferences. Navigate down to Ruby: Interpreters. Edit your interpreter, and set the Interpreter arguments to -rubygems. That made my installation see the ruby gems I had installed.

To check which gems you have installed, use this command in a terminal:

gem query --local
Don Kirkby
  • 53,582
  • 27
  • 205
  • 286
0

I'm not sure of the exact steps to configure eclipse, but you might want to check out Aptana Studio. I used it a while back when it was known as RadRails and it was great. It's an eclipse based IDE that works with Ruby and Ruby on rails out of the box.

Jay Prall
  • 5,295
  • 5
  • 49
  • 79