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

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.

Related

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

Ruby not finding rubygems or wx modules

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.

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.

OSX Ruby Gems Add to ruby path?

I am just starting to learn ruby. It seems that the default gems install path is not part of Ruby. Is this normal behavior? How can I set the default ruby path? Example:
[11:53:33]wuntee:/Library/Ruby/Gems/1.8/gems/packetfu-1.0.0/examples$ sudo ruby arphood.rb
Fetching the oui.txt from IEEE, it'll be a second. Avoid this with arphood.rb <filename>.
arphood.rb:30:in `require': no such file to load -- packetfu (LoadError)
from arphood.rb:30:in `arp_everyone'
from arphood.rb:51
As you can see packetfu is installed in /Library/Ruby/Gems/1.8/gems/, but ruby cant find it...
that's because you're not in the directory where packetfu.rb file lies and there's no require 'rubygems' to add the gems paths in your script

Resources