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

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

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 'nokogiri' issue with Ruby 1.9.2

I have made a Ruby project (not rails project) in Netbeans, and in main.rb file i have been requiring nokogiri but i am getting the following error.
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- nokogiri (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
from /home/nadeem/rails_project/RubyApplication1/lib/main.rb:2:in `<main>'
I have installed nokogiri 1.5.0 and using ruby 1.9.2
Any idea?
Using bundler to manage your gem dependencies is probably a good idea because you can check if things are set up properly using bundle check if you've declared and successfully installed them.
The bundler setup routine can import many gems in the proper order, accounting for dependencies. Otherwise you will need to have at least this:
require 'rubygems'
gem 'nokogiri'
require 'nokogiri'
Make sure that the gems are installed with the same version of Ruby you're trying to run. It's easy to get mixed up when you're using rvm and have inadvertently added the gems to a different version.
Refer to this solution hope this will be helpful, Check your net bean's project properties and try to update path from there.
Require Nokogiri? No such file to load

How to install Ruby gem automatically, if required?

Given a Ruby program that uses a particular gem (e.g. term-ansicolor), how could I install the gem automatically, if required?
In other words, the program does:
require 'term/ansicolor'
and, in case the gem wasn't install previously, I would like to install it and continue the program rather than getting an error:
LoadError: no such file to load -- term/ansicolor
from (irb):1:in `require'
from (irb):1
from :0
What would be the most appropriate method to achieve that?
I've been using this pattern:
require 'rubygems'
begin
gem 'minitest'
rescue Gem::LoadError
Gem.install('minitest')
gem 'minitest'
end
require 'minitest'
Such a tool is not available. Read a detailed discussion about it here http://www.ruby-forum.com/topic/2728297
You should consider to use bundler. It's the de-facto standard way to manage dependencies in Ruby software.
Alternatively, you could build your package into a gem and put the required gem as a dependency in the gemspec. It would then get installed automatically when you install the gem.

couch_potato : no such file to load -- json/add/rails

When I 'require' the couch_potato gem, I get the following error:
LoadError: no such file to load -- json/add/rails
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:59:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:59:in `require'
from /Library/Ruby/Gems/1.8/gems/couch_potato-0.5.7/lib/couch_potato.rb:4
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:59:in `gem_original_require'
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:59:in `require'
from (irb):1
I'm not particularly experienced with Ruby yet so took a shotgun type approach and uninstalled all my gems, then reinstalled starting with couch_potato. The json gem is a requirement so the latest version was installed automatically. But this issue has persisted.
I thought maybe this part of rails (because 'rails' is in the error ... it seems like a long shot but as mentioned I'm very new to Ruby and not completely sure how gems work yet :)) but the install ended abruptly after the following few lines (these are the last few lines after a very long list):
Installing RDoc documentation for rack-ssl-1.3.2...
Installing RDoc documentation for rdoc-3.9.4...
Installing RDoc documentation for railties-3.1.0...
Installing RDoc documentation for bundler-1.0.18...
Installing RDoc documentation for rails-3.1.0...
file 'lib' not found
But anyway I went looking for the missing file. In the gem folder (/Library/Ruby/Gems/1.8/gems/json-1.1.9) there is 'lib' then 'json/add' which is a minor victory, but there is no 'rails' file in there.
At this point I checked my laptop ... there is an older version of 'json', but the file 'json/add/rails' does exist in that older gem.
What is my best option at this point? Is there a different version of couch_potato I should be using? Can I make couch_potato use the older json gem version?
You need to install the JSON gem.
$ gem install json
Actually, the json/add/rails file is deprecated by the JSON library
# This file used to implementations of rails custom objects for
# serialisation/deserialisation and is obsoleted now.
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
require 'json'
end
$DEBUG and warn "required json/add/rails which is obsolete now!"
but it seems couch_potato has not been updated and the require is still in place.

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