tl;dr
Pry can't find several of my installed gems because the gems found by Gem::Specification are different than the gems found by gem list --local. The ruby versions are the same, and the path to the found and not-found gems seems to be the same.
I'm thinking that I must have some mix up with paths or ruby versions, but I can't find the culprit. Any ideas of how to untangle this?
Details
I'm running ruby 2.2.0 using rvm on OS X Yosemite, and I'm having an issue getting pry to find several of my installed gems (in particular, pry-doc).
Here are my versions:
lee$ ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
lee$ pry -v
Pry version 0.10.1 on Ruby 2.2.0
lee$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.6
- RUBY VERSION: 2.2.0 (2014-12-25 patchlevel 0) [x86_64-darwin14]
- INSTALLATION DIRECTORY: /usr/local/rvm/gems/ruby-2.2.0
- RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-2.2.0/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/rvm/gems/ruby-2.2.0/bin
- SPEC CACHE DIRECTORY: /Users/lee/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-14
- GEM PATHS:
- /usr/local/rvm/gems/ruby-2.2.0
- /usr/local/rvm/gems/ruby-2.2.0#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--omg"
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/rvm/gems/ruby-2.2.0/bin
- /usr/local/rvm/gems/ruby-2.2.0#global/bin
- /usr/local/rvm/rubies/ruby-2.2.0/bin
- /usr/local/rvm/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/git/bin
- /opt/sm/bin
- /opt/sm/pkg/active/bin
- /opt/sm/pkg/active/sbin
- /opt/sm/bin
- /opt/sm/pkg/active/bin
- /opt/sm/pkg/active/sbin
Listing gems via the command line returns what I expect:
lee$ gem list --local | grep 'pry'
pry (0.10.1)
pry-doc (0.8.0)
pry-git (0.2.3)
pry-nav (0.2.4)
pry-rails (0.3.4)
And the paths for both pry and bash seem to be the same
lee$ gem which pry
/usr/local/rvm/gems/ruby-2.2.0/gems/pry-0.10.1/lib/pry.rb
lee$ gem which pry-doc
/usr/local/rvm/gems/ruby-2.2.0/gems/pry-doc-0.8.0/lib/pry-doc.rb
pry(main)> $ pry
From: /usr/local/rvm/gems/ruby-2.2.0/gems/pry-0.10.1/lib/pry/core_extensions.rb # line 41:
...
However, in pry, the gems available to be installed are controlled by Gem::Specification from the rubygems library. Running the following:
# I know this method is a mess, but it does the job
def prys
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }
.select { |g| g.name =~ /pry/ }
.group_by{ |g| g.name }
.map { |name, versions|
"#{name} (#{versions.map { |v| v.version.to_s }.join(', ') })"
}
end
prys
returns:
=> ["pry (0.10.1)", "pry-rails (0.3.4)"]
I've tried uninstalling and reinstalling as well as hunting around for another copy of the found gems, but no luck. I can't figure out the pattern for what's being returned either.
Any ideas of what to try next?
I couldn't figure it out, so I figured that there was some issue with how my gems were being saved. I tried rvm remove 2.2.0 --gems and then reinstalling, and that solved the issue.
I'm still not sure what precisely was the problem, so if anyone has next-level troubleshooting steps, that's probably still be useful to share.
I had the same problem with pry-rails and ruby 2.3.0, rails 4.2.6. I use rvm to remove ruby and install it again, and everything works.
However, come to think of it, I guess that the real problem is spring is running somewhere with an old gemset. After you install the gem using bundler, you should type spring stop, then run rails c again. It should run ok.
Related
I've installed a number of gems, however when i go to 'require' them i get "no such file to load error":
~/Documents/Projects/Ruby Scripts/Domain » ./whois.rb
/System//Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in 'require': cannot load such file -- whois (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from ./whois.rb:3:in `<main>'
I have installed the gem and it appears to have installed sucessfully:
~ » gem install whois
Fetching: whois-4.0.1.gem (100%)
Successfully installed whois-4.0.1
Parsing documentation for whois-4.0.1
Installing ri documentation for whois-4.0.1
Done installing documentation for whois after 0 seconds
1 gem installed
Running gem list shows the gem installed as a local gem:
*** LOCAL GEMS ***
activesupport (5.1.0)
addressable (2.5.1)
...
whois (4.0.1)
Running gem env shows the gem path that i would expect as i am using rbenv:
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.11
- RUBY VERSION: 2.4.1 (2017-03-22 patchlevel 111) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /Users/perfektion/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0
- USER INSTALLATION DIRECTORY: /Users/perfektion/.gem/ruby/2.4.0
- RUBY EXECUTABLE: /Users/perfektion/.rbenv/versions/2.4.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/perfektion/.rbenv/versions/2.4.1/bin
- SPEC CACHE DIRECTORY: /Users/perfektion/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/perfektion/.rbenv/versions/2.4.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /Users/perfektion/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0
- /Users/perfektion/.gem/ruby/2.4.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/perfektion/.rbenv/versions/2.4.1/bin
- /usr/local/Cellar/rbenv/1.1.0/libexec
- /Users/perfektion/.rbenv/shims
- /Users/perfektion/.rbenv/bin
- /Users/perfektion/.rbenv/shims
- /Users/perfektion/.rbenv/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
Checking the gem path for the gem whois and i can see it located there.
Strangely though irb seems to be able to locate the gem:
~/ » irb
irb(main):001:0> require 'whois'
=> true
irb(main):002:0> whois = Whois::Client.new
=> #<Whois::Client:0x007fbc121074c8 #timeout=10, #settings={}>
I have been troubleshooting this for about 24 hours now and i feel like i am losing my mind. This issue has only become apparent in the past 24-48 hours. Prior to that the scripts i was playing with were working fine.
Potentially Useful Info
Running OSX Sierra 10.12.4
I am using rbenv and ruby-build
Using Ruby 2.4.1 set globally
PATH = /Users/perfektion/.rbenv/shims:/Users/perfektion/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Re-installed rbenv, ruby-build, ruby and removed all gems and re-installed.
I feel like it is something stupid, but can anyone see what i am doing wrong here that would be causing ruby to not be able to find these gems?
Thank you!
Update
Not sure why i didn't pick this up earlier, but in the top of my script i have:
#!/usr/bin/ruby
I am not sure why this worked before and it isn't now.
Thanks for the help everyone :)
Whenever you try to run the file it's looking for the gem in the Ruby 2.0 directory. Whenever you do gem env it's showing 2.4.1 as your ruby version.
Keep in mind that with rbenv you can either set a local, global, or shell level version of ruby to run: https://github.com/rbenv/rbenv#rbenv-local
You can also create a .ruby-version file in a directory, and rbenv will look for that and use that version if it exists. Something is off between which version of ruby you are using to install the gem and which one is being used to run your whois script.
when you type ./whois.rb you call the ruby system.
try use ruby ./whois.rb
It will call the RVM/rbenv loaded ruby system
Because ruby is trying to fetch the library from another path that is not the same as the one you installed the wois gem with rbenv. (What could be some conflict with rvm and rbenv, I do not know.)
Try to create a new folder, set ruby 2.4 locally with local rbenv <version> and then try to make require again.
I recently installed Ruby 2.0.0 on OS X 10.8.3 by compiling from source code. I checked the version with
$ ruby --version
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]
And I checked my gem version with
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-12
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/ehartsuyker/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :benchmark => false
- :sources => ["http://rubygems.org/", "http://gemcutter.org"]
- REMOTE SOURCES:
- http://rubygems.org/
- http://gemcutter.org
I noticed that the reported version of Ruby here does not match the version I installed. I don't know if this matters or not.
I have a simple piece of code called encrypy.rb that I'm running. After installing the 'rsa' gem with gem install rsa.
require 'rubygems'
require 'rsa'
key = RSA::KeyPair.generate(128)
ciphertext = key.encrypt("message")
puts(ciphertext)
When I run it, it gives an error saying it can't find the gem.
$ ruby encrypt.rb -Idirectory '/Library/Ruby/Gems/1.8'
/usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- rsa (LoadError)
from /usr/local/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from encrypt.rb:2:in `<main>'
So the question is, why isn't Ruby finding the gem despite seeming to know where it is? And how can I fix it?
Ruby 1.8.7 is shipped with OS X. It seems that gem is seeing that version instead of your manually installed 2.0.0. As others already suggested, using RVM or rbenv (which one depends on personal preference) makes handling different ruby environments much easier. You can find those tools and descriptions for them in the following places:
RVM: https://rvm.io/
rbenv: https://github.com/sstephenson/rbenv
I'm trying to install gems on my ruby installation... I've installed a few, like heroku, yet when i list my local gems, the only one i see is Rake, and of course heroku cannot be used...
Any idea how i can solve this? What could the issue be? Installation for Heroku gem sewems to go smooth using sudo gem install heroku...
here is my gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.6
- RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [i686-linux]
- INSTALLATION DIRECTORY: /home/alex/.rvm/gems/ruby-1.9.2-p290
- RUBY EXECUTABLE: /home/alex/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
- EXECUTABLE DIRECTORY: /home/alex/.rvm/gems/ruby-1.9.2-p290/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/alex/.rvm/gems/ruby-1.9.2-p290
- /home/alex/.rvm/gems/ruby-1.9.2-p290#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Thx!
I see that you use rvm to maintain your gems. Please do not use sudo to install the gems in that case.
RVM doesn't recognize gems installed with sudo and seems to be buggy even when you aren't using the sudo installed gems.
The ultimate solution that worked for me to uninstall all the gems locally and with sudo. Here is what to do:
$sudo gem list and $gem list to grab the gems you want. Save those as a .gems file using a text editor. The .gems file is just a listing of the gems, one per line, with the version number after (e.g. nokogiri -v1.4.3.1)
uninstall all of the gems. You can do this in bulk by just listing the gems with a space separated between them. $sudo gem uninstall gem1 gem2 gem3
use the directions at https://rvm.beginrescueend.com/gemsets/importing/ to import the newly made .gems list.
I was having some trouble running some Ruby scripts. While trying to get these scripts to run I tried lots of different things as well as updating rubygems as I thought this may be the problem. Since then I can't get any Ruby scripts to run.
I think that if I can revert rubygems back to it's original version I may be able to run Ruby scripts again, but I don't know how.
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/ryan/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://gems.rubyforge.org/
$ ruby -v
ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin10]
$ which -a ruby
/opt/local/bin/ruby
/opt/local/bin/ruby
/usr/bin/ruby
/usr/local/bin/ruby
$ which -a gem
/usr/bin/gem
/usr/local/bin/gem
Thank you for any help in advance.
Ryan
$ ruby spidr_start_at.rb
spidr_start_at.rb:1:in `require': no such file to load -- rubygems (LoadError)
from spidr_start_at.rb:1
$ cat spidr_start_at.rb
require 'rubygems'
require 'uri'
require 'spidr'
url = 'http://www.ethicalhack3r.co.uk'
puts "Spidr.start_at()"
puts
Spidr.start_at(url, :depth => 1) do |spider|
spider.every_page do |page|
puts page.url.to_s
end
end
It seems that you have multiple versions of ruby(and gem) installed. It is advised to use rvm when maintaining multiple ruby versions. Or clean up your wrong/old/unneeded installations.
For downgrading Rubygems, you can do the following:
sudo gem update --system VERSION
You obviously have to put a real version there.
I've installed the development version of Crunchbang, a linux distro based off Debian. I got Ruby and Rubygems installed, but I can't get the gems I've installed to load. Here is a command-line session:
$ ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i486-linux]
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.6
- RUBY VERSION: 1.9.1 (2010-01-10 patchlevel 378) [i486-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby1.9.1/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/lib/ruby1.9.1/gems/1.9.1
- /home/corey/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
$ echo $PATH
/home/corey/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/home/corey/.gem/ruby/1.9.1:/usr/lib/ruby1.9.1/gems/1.9.1
$ gem list -d nokogiri
`*** LOCAL GEMS ***`
nokogiri (1.4.1)
Authors: Aaron Patterson, Mike Dalessio
Rubyforge: http://rubyforge.org/projects/nokogiri
Homepage: http://nokogiri.org
Installed at: /usr/lib/ruby1.9.1/gems/1.9.1
Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser
$ ruby -r rubygems -e "require 'nokogiri'"
-e:1:in `require': no such file to load -- nokogiri (LoadError)
from -e:1:in `'
I've encountered similar problems on Ubuntu before, but they were easy to fix. I can't figure out what's wrong in this particular case, and Google didn't seem to know either. Any help would be greatly appreciated!
By the way... this is my first submission to stackoverflow. I hope this question is relevant. :)
Debian does not load RubyGems by default. You can solve this by adding require 'rubygems' to your code or better still, have RubyGems loaded each time Ruby is run. I also run #! and achieved this by editing my ~/.profile adding export RUBYOPT=rubygems and finally reloading my profile with . ~/.profile.
For more information on this matter see: http://docs.rubygems.org/read/chapter/3
Is nokogiri in any of the directories in GEM PATHS?
I've had problems before with installing rubygems from the Debian repos and then installing in manually. Debian puts all gems in /var/ somewhere in the distribution package.