Question

I installed Dynamic Languages Toolkit for Ruby plugin in eclipse and it is not working:

Details:

  • Eclipse version: Eclipse 4.2.2
  • OS Details: Ubuntu 10.04
  • Ruby version: ruby 1.9.2p180

THis is my ruby code:

# cat array.rb 
#!/usr/bin/ruby
require "awesome_print"

hash = {
        :name => "your_self",
        :place => ["where", "somewhere"],
} 
ap hash

and here is the ERROR when this is run from eclipse:

<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- awesome_print (LoadError)

HOwever, I can run this code from console manually and it gives me the output:

# ruby array.rb 
{
     :name => "your_self",
    :place => [
        [0] "where",
        [1] "somewhere"
    ]
}

Needless to say, I do have awesome_print gem installed:

# gem list | grep awesome
awesome_print (1.2.0)

In Eclipse, I do have ruby interpreter set as below: enter image description here

QUESTION: This issue is seen only when I use require in my code. Otherwise Eclipse can run the ruby code fine. What am I missing in my eclipse?

UPDATE:

If I use:

require "/usr/local/lib/ruby/gems/2.0.0/gems/awesome_print-1.2.0/lib/awesome_print.rb"

then Eclipse is able to run the code fine. So I think this has something to do with ruby/eclipse search path of something.

Was it helpful?

Solution

Something weird is going on. Instead of #!/usr/bin/ruby, I had to make it #!/usr/local/bin/ruby.

I had to make similar changes in ruby interpreter setting in eclipse. Now my code is working fine.

So, Now I realized I actually have two versions of ruby installed:

# /usr/bin/ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
# /usr/local/bin/ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [i686-linux]

I don't know how the version 2.0.0 got installed.

I had installed only 1.9.2. and then ran gem install awesome_print

So, if I change the shebang and eclipse to use the ruby 2.0.0, it is working fine. Probably, my awesome_print got installed only for 2.0.0

This is so confusing. Anyway. I am good now. Ruby learning !!!

But then again, how come I was able to run the same program fine from command line even with ruby verion 1.9.2 ?

UPDATE:

So, I was wrong, When I ran ruby array.rb it was actually running /usr/local/bin/ruby and hence it worked from the command line. But in eclipse, I had set the ruby interpreter as /usr/bin/ruby which was 1.9.2. and it was giving errors.

I could reproduce the same error from command line by running /usr/bin/ruby array.rb.

So...

This means, my installation of ruby 1.9.2 is not good. I still don't know where ruby 2.0.0 came from. But Now, I should uninstall and get rid of 1.9.2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top