Ruby not finding rubygems or wx modules - ruby

I'm running the default Ruby installation (ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10]) on my Intel iMac. I updated RubyGems and installed the wxruby gem. I'm trying to run the following sample program:
#!/usr/bin/ruby
require "rubygems"
require "wx"
class MyApp < Wx::App
def on_init
#frame = Wx::Frame.new(nil, -1, "The Bare Minimum")
#frame.show()
end
end
app = MyApp.new()
app.main_loop()
And I get the following error:
==> wxruby-test.rb
/Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wxruby2.bundle: dlopen(/Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wxruby2.bundle, 9): no suitable image found. Did find: (LoadError)
/Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wxruby2.bundle: no matching architecture in universal wrapper - /Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wxruby2.bundle
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
from /Library/Ruby/Gems/1.8/gems/wxruby-1.9.3-universal-darwin/lib/wx.rb:12
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:60:in `require'
from wxruby-test.rb:3
If I comment out the require rubygems statement, I get the following error:
==> wxruby-test.rb
wxruby-test.rb:3:in `require': no such file to load -- wx (LoadError)
from wxruby-test.rb:3
I'm new to Ruby on the Mac, and I'm sure this is some basic error probably related to paths, but most explanations about the environment variables are aimed at experienced users. If you need more output from other commands, please let me know. I'm running Ruby from the tcsh shell. I'm sure I'm doing something basic wrong, but I'm just stumped.

If you're running Ruby 1.8.7 you should leave in the require statement:
require "rubygems"
Ruby 1.8 didn't know about gems by default, so we had to tell Ruby to require the gems loader. Ruby 1.9+ bundles it so we no longer have to do the require.
This has nothing to do with the Mac (or Windows or Linux) OS, it's about Ruby's default load paths.
And, as a safety tip, don't mess with Ruby installed by Apple. They installed it for their own use, and it's used for some podcast-creation tools. And, at some future point they might want to add something to the system that takes advantage of an expected configuration of Ruby (or Python or Perl). Changing (or worse, deleting it) can mess you up. So, I recommend you leave it alone and use either rbenv or RVM to install Ruby in a sandbox, where you can poke, prod and mess with it safely.

What version of OS X? If it's one of the Lions, then you're out of luck. The wxwidgets library (and things based on it, like wxruby) is still only 32-bit and based on Carbon. The Lions are 64-bit-only and Carbon is deprecated.

Related

cannot load such file -- rubygems.rb (LoadError)

I'm new to ruby. I removed ruby 1.9 with sudo apt-get purge ruby and then
I installed ruby 2.3.0 using ruby-install. But I got the following error
<internal:gem_prelude>:4:in `require': cannot load such file -- rubygems.rb (LoadError)
from <internal:gem_prelude>:4:in `<internal:gem_prelude>
when running rspec my_script.rb.
Still can't fix this after googling! Anyone can help me out?
It seems that the rspec binary was only installed for your previous ruby version. Therefore it is found, but not guaranteed to work.
I'd recommend to use something like rvm (https://rvm.io/) or rbenv (https://github.com/rbenv/rbenv). Both of them can easily handle different ruby versions while maintaining dependencies (e.g. different load paths, different gem versions, etc.). I'd even use rvm if there is only one single ruby version installed on a system.

`require': cannot load such file -- oauth

I was happily using Emacs's evernote-mode until stupidly removed OS X system ruby (I'm on Yosemite). Then I tried installing one via RVM (first tried 2.0 then 1.9), got all necessary gems, yet thing is still broken. Throws this message:
$HOME/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- oauth (LoadError)
from $HOME/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:54:in `require'
from $HOME/.rvm/rubies/ruby-1.9.3-p551/bin/enclient.rb:40:in `<main>'
Please help me to fix that
upd: I don't see the point of reinstalling system ruby (as people suggested) and then having it conflicting with those that I want to use via RVM. Ruby developers advise to use RVM. I symlinked my default Ruby to /usr/bin/ruby.
I seems that specific script uses something I don't have. I remember having hard time figuring out all dependencies and gems and installing them the first time I used that script and after hours of investigating it finally worked. But this time I got stuck.
I tried to run the script outside of Emacs and it runs with no errors (maybe that's not enough to find what's broken)
I tried to run irb and require modules one by one. It says => true until reaches require 'oauth/consumer'. I guess that's what's missing maybe? I run gem install oauth_consumer. It installed few gems, and now says => true for oauth/consumer in irb, the script though still doesn't work
i removed systems ruby once. i just had to go to the trash and put back everything i deleted and it worked for me. don't know how you "removed" your system ruby. besides, if you installed one with RVM then you have to tell RVM to choose and use/set a default ruby. because RVM won't install ruby 1.9.1 (rather a higher version which i think you did). So you have to set to that version.
Like this:
$ rvm --default use 2.1.5
don't forget to install oauth as well. Hope it helps.

rvm does not import gem path

I’m running on Mac OS X Yosemite 10.10 Beta 3, I did a fresh install of rvm (removed everything I could think of and reinstalled the whole thing.
Attempting to run a scripts I had working on Mavericks.
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ gem install restclient
Successfully installed restclient-0.10.0
Parsing documentation for restclient-0.10.0
Done installing documentation for restclient after 0 seconds
1 gem installed
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ which irb
/Users/maximveksler/.rvm/rubies/ruby-2.1.2/bin/irb
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ irb
2.1.2 :001 > require 'restclient'
LoadError: cannot load such file -- restclient
from /Users/maximveksler/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/maximveksler/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from (irb):1
from /Users/maximveksler/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>’
Path looks normal
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ env | grep GEM
GEM_HOME=/Users/maximveksler/.rvm/gems/ruby-2.1.2
GEM_PATH=/Users/maximveksler/.rvm/gems/ruby-2.1.2:/Users/maximveksler/.rvm/gems/ruby-2.1.2#global
Also the gem is installed
Maxims-MacBook-Air:AppleSampleCodeWorker maximveksler$ file /Users/maximveksler/.rvm/gems/ruby-2.1.2/gems/restclient-0.10.0/lib/rest_client.rb
/Users/maximveksler/.rvm/gems/ruby-2.1.2/gems/restclient-0.10.0/lib/rest_client.rb: ASCII C++ program text
So what am I missing ?
Looking at your link here, there is an error in your syntax. It should be require 'rest_client' rather than require 'restclient'. The reason that your version still works is as you said because there is a file called restclient.rb which is used as the source for the additional restclient binary that the gem supplies (which is against regular naming convention, you should file an issue with the github).
Now because you require this file (restclient.rb) which is used to set up an environment that already has RestClient available, it is effectively the same as requiring rest_client. It may however have unintended consequences so you should probably stick to the convention outlined in the documentation.
This is all from reading the documentation here and glancing at the files here. Does that make sense? I worried it was unclear as the two files are very similar.

How do i install the latest version of Ruby on Mac?

After installing Ruby 2.0, I try and run my .rb file, and get this error:
/Users/Andrew/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require': cannot load such file -- ruby-box (LoadError)
from /Users/Andrew/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:51:in `require'
from box.rb:2:in `<main>'
My code:
require "rubygems"
require "ruby-box"
Have you installed ruby-box for your new Ruby? Try running this, and trying again:
gem install ruby-box
Also note that require "rubygems" is useless and redundant (the interpreter deals with all this for you) in Ruby 1.9 and onwards.
I recommend using bundler to manage your dependencies even if it is a small project. It provides install and update tools to help mitigate these exact problems. For example, you could update all your dependencies with one command:
bundle update
The time invested learning bundler will quickly pay for itself :D

How to enable ruby to see tk in the require tk statement?

I am starting to learn the very basics of ruby on my iMac running Leopard.
The version that is now on my system is ruby 1.8.6
But, I independently also installed ( via MacPorts ) ruby 1.9 because that corresponds to the latest "PickAxe" book.
The installation location for ruby 1.8.6 is in /usr/bin/ruby
The installation location for ruby 1.9.1 is in /opt/local/bin ( installed there when I used MacPorts )
My question has to do with an error message related to the require 'tk' statement in
following fairly standard example, which is in the file HelloWorld.rb
require 'tk'
root = TkRoot.new { title "Hello world" }
TkLabel.new(root) do
text 'Hello world!'
end
Tk.mainloop
When I invoke the command
ruby HelloWorld.rb
I get the results I expect; the program runs.
However, when I invoke the command
ruby1.9 HelloWorld.rb
I get the error message
HelloWorld.rb:1:in require': no such file to load -- tk (LoadError)
from HelloWorld.rb:1:in'
I have been searching the web and various postings but so far have not been able
to find a clear explanation of what I need to do to make ruby1.9 be able to find tk
when using the require 'tk' statement.
Does it have to do with running the gem1.9 command ( which is also in /opt/local/bin )?
I have tried invoking
sudo gem1.9 install tk
but that results in an error message
ERROR: could not find gem tk locally or in a repository
Any suggestions would be greatly appreciated.
The TK bindings for ruby use compiled code (and not pure ruby), so two installations are needed for different ruby versions.
Darwinports isn't building ruby 1.9 with TK support by default. You need to select either the tk or mactk variant (see the portfile)
It's been a while since I've used darwinports, but I think this was the syntax:
port install ruby19 +mactk
You need to compile ruby using the with-tcltk-framework flag in your ./configure call. Full details can be found on the TkDocs - Installing Tk page. The first section is Mac OS X, and then the portion of that with the Ruby logo next to it is just what you need.
Another thing worth noting is the website recommends against using Ruby 1.9.x for Tk. However, the only way to know for sure if it will work is trying it out yourself.

Resources