I execute for instance:
gem list
and I get this:
abstract (1.0.0)
actionmailer (3.2.1, 3.1.3, 3.1.1, 3.0.5)
actionpack (3.2.1, 3.1.3, 3.1.1, 3.0.5)
activemodel (3.2.1, 3.1.3, 3.1.1, 3.0.5)
(...)
uglifier (1.2.3, 1.2.2, 1.1.0, 1.0.3)
webrat (0.7.3)
xpath (0.1.4)
Them if I try with
irb --simple-prompt
>> require 'webrat'
I get
LoadError: no such file to load -- webrat
from (irb):1:in `require'
from (irb):1
from :0
And this happens with every Gem on the list. What's wrong? I'm using Ubuntu 11.10. Sorry if this is dumb, but I got stuck.
You need to require rubygems before you can require any gems. You can do this in irb:
$ irb --simple-prompt
>> require 'rubygems'
>> require 'webrat'
or when starting irb up:
$ irb --simple-prompt -r rubygems
>> require 'webrat'
Ruby 1.9 package now includes RubyGems by default on most platforms.This means that on Ruby 1.9 and above, you will not need to require 'rubygems' in order to load gem libraries.
if you use like this: require 'rubygems'
The big problem with this approach is that you don’t want to make this change to every single Ruby program you download!
While ok for quick scripts you write yourself, this is not the way to go.
Related
I am using ruby version 2.3.3p222
Here is my Gemfile:
# Gemfile
source 'https://rubygems.org'
gem 'pry'
I run bundle and here is the resulting Gemfile.lock
Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.2)
method_source (0.9.2)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
PLATFORMS
ruby
DEPENDENCIES
pry
BUNDLED WITH
1.15.1
I then simply run a ruby script via ruby my_report.rb (this script is located in the same directory as Gemfile and Gemfile.lock). my_report.rb only has this in the file:
require 'pry'
Here is the error:
WARN: Clearing out unresolved specs.
Please report a bug if this causes problems.
/Users/<user>/.rvm/gems/ruby-2.3.3/gems/pry-rescue-1.4.5/lib/pry-rescue.rb:15: warning: method BaseHelpers#windows? is deprecated. Use Pry:Helpers::Platform.windows? instead
/Users/<user>/.rvm/gems/ruby-2.3.3/gems/pry-stack_explorer-0.4.9.2/lib/pry-stack_explorer.rb:128:in `<top (required)>': undefined method `before_command' for #<Pry::CommandSet:0x007fccdcf0b1e8> (NoMethodError)
Question: What am I missing? How can I properly require in pry into my ruby script so that I can set breakpoints?
What eventually worked for me is I just uninstalled all of the pry versions I had installed via gem uninstall. Then: in my gemfile I specified a previous version of 0.11.3:
# Gemfile
source 'https://rubygems.org'
gem 'pry', '0.11.3'
I did bundle install and then ran my ruby script, and that worked for me.
When I require 'active_support/core_ext', then get a error :
NameError: uninitialized constant ActiveSupport::Autoload from /opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0/lib/active_support/number_helper.rb:3:in `<module:NumberHelper>'
Of course I installed activesupport gem.
# gem list --local | grep activesupport
activesupport (4.2.0)
Should I install some other gems to use active_support/core_ext?
I'm using ruby 2.1.5p273 in Ubuntu14.04.
Presuming you're using bundler, try this diagnostic code to see what works:
require 'rubygems' # You may be able to omit this line
require 'bundler/setup' # You may be able to omit this line
require 'active_support'
require 'active_support/core_ext'
Newer Ruby versions may be able skip rubygems, setup, and core_ext, and just use this:
require 'active_support'
I have installed the sys-proctable gem on a fresh Ubuntu image (running via Vagrant)
with Ruby 1.8.7.
vagrant#precise64:~$ gem list
*** LOCAL GEMS ***
bunny (0.7.9)
chef (10.14.2)
...many, many gems more
sys-proctable (0.9.3 universal-linux)
systemu (2.5.2)
treetop (1.4.10)
uuidtools (2.1.3)
yajl-ruby (1.1.0)
now I want to load it into irb
vagrant#precise64:~$ irb
irb(main):001:0> require 'sys/proctable'
LoadError: no such file to load -- sys/proctable
from (irb):1:in `require'
from (irb):1
from :0
so what is the issue here?
You may need to require rubygems first. I think then it will work.
Also: are you sure you need to use a / and not a -?
Obviously you managed to load it...
Just wanted to make sure everything is written.
It's definitely a / that's required.
This should work :
require 'rubygems'
require 'sys/proctable'
....
I've got a simple script that uses sinatra. Should be simple, right? Apparently not.
The code:
require 'rubygems'
require 'sinatra'
That's all there is. And it fails, saying:
tekknolagi#eos ~/indexer $ ruby torrent.rb
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- torrent-ruby (LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from torrent.rb:2
I gem installed it several times over, just to make sure I wasn't going crazy. What could be going wrong and how can I fix it?
Oh, and here's my list of installed gems:
tekknolagi#eos ~/indexer $ gem list
*** LOCAL GEMS ***
rack (1.4.1)
rack-protection (1.2.0)
rake (0.9.2.2)
sinatra (1.3.2)
sqlite3 (1.3.6)
tilt (1.3.3)
torrent-ruby (0.1.4)
I believe you have done everything right. Many times this custom require error appears when the gem is not installed in the proper path. Try not using the explicit require. Use this instead..:
require_relative 'sinatra'
I am running Ruby 1.9.2. I have rake 0.8.7 installed. However running rake inside a Rails application gives me the following:
(in /usr/home/users/dimitar/Rails/spek)
Could not find activesupport-3.0.1 in any of the sources
Try running `bundle install`.
So I go ahead and run bundle install again and everything looks good:
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.1)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.1)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.1)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.8)
Using mail (2.2.7)
Using actionmailer (3.0.1)
Using arel (1.0.1)
Using activerecord (3.0.1)
Using activeresource (3.0.1)
Using bundler (1.0.3)
Using thor (0.14.3)
Using railties (3.0.1)
Using rails (3.0.1)
Using sqlite3-ruby (1.3.1)
Your bundle is updated! Use `bundle show [gemname]` to see where a bundled gem is installed.
But rake still gives me the same error message. Any suggestions?
Actually the problem seems to come from the config/boot.rb file:
# Set up gems listed in the Gemfile.
gemfile = File.expand_path('../../Gemfile', __FILE__)
begin
ENV['BUNDLE_GEMFILE'] = gemfile
require 'bundler'
Bundler.setup
rescue Bundler::GemNotFound => e
STDERR.puts e.message
STDERR.puts "Try running `bundle install`."
exit!
end if File.exist?(gemfile)
Do you have multiple Ruby interpreters installed (maybe via rvm or some other method)? If so, are you sure that the right one is active?
Things to look at:
which ruby
which rake
ruby -e 'puts $:' # To show the LOAD_PATH for gems
I had a similar problem using ruby-1.9.2 and fixed it by upgrading rubygems
sudo gem update --system
I had the same problem when I was using REE 1.8.7. I switched to 1.9.2 and did bundle install. Then my rake commands worked.
I had this issue when I mistakenly ran passenger with ruby 1.9.3 and the app used 1.8.7 in its .rvmrc. Fixed by using 1.9.3 (now I have encoding problems, but thats a different story).