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.
Related
I am running OSX High Sierra.
I have a ruby script I'm attempting to run on OSX (it's an Avid validation tool, but I don't think that matters).
When I run it, I get the following output ( added the code to print the version and the gem path)
MacBook-Pro:DTT jon$ ./run_test.command -h -v
-----
Ruby Version : 2.5.0
Gem Path :
/Users/jon/.gem/ruby/2.5.0
/Users/jon/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0
-----
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- curses (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/jon/Downloads/AAX_Tools_DSH_0p2p1x753_2/DTT/sources/DishTestTool.rb:21:in `<top (required)>'
from /Users/jon/Downloads/AAX_Tools_DSH_0p2p1x753_2/DTT/sources/bin/runsuite.rb:82:in `require_relative'
from /Users/jon/Downloads/AAX_Tools_DSH_0p2p1x753_2/DTT/sources/bin/runsuite.rb:82:in `<main>'
Note that it appears to be reading gems from version 2.3, but I am actually running 2.5.0
and if I do gem env, there is no sign of that 2.3 folder
MacBook-Pro:DTT jon$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.7.6
- RUBY VERSION: 2.5.0 (2017-12-25 patchlevel 0) [x86_64-darwin17]
- INSTALLATION DIRECTORY: /Users/jon/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0
- USER INSTALLATION DIRECTORY: /Users/jon/.gem/ruby/2.5.0
- RUBY EXECUTABLE: /Users/jon/.rbenv/versions/2.5.0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/jon/.rbenv/versions/2.5.0/bin
- SPEC CACHE DIRECTORY: /Users/jon/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/jon/.rbenv/versions/2.5.0/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-17
- GEM PATHS:
- /Users/jon/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0
- /Users/jon/.gem/ruby/2.5.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/jon/.rbenv/versions/2.5.0/bin
- /usr/local/Cellar/rbenv/1.1.1/libexec
- /Users/jon/.rbenv/shims
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /opt/local/bin
- /opt/X11/bin
I've tried installing ruby with rvm, then uninstalled it, removed rvm, installed it again with rbenv. Installing and updating gems (curses in particular), etc etc (I'm a newbie with ruby and moderately familiar with the workings of Unix systems, but no systems guru), but all to no avail.
Does anybody know how I get ruby to read the correct gems?
--------------- Edit ----------------
I've discovered cause of the issue
The ruby script run_test.command called another ruby script, with the line
system("#{ruby} \"#{runsuite_path.realpath}\" #{args}")
Where, crucially
ruby = '/usr/bin/ruby'
For some reason, updating ruby does not change the version of ruby executed with /usr/bin/ruby
changing that line to
ruby = '/usr/bin/env ruby'
Seems to fix the issue
Which begs two questions. Why is /usr/bin/ruby not changed to reflect the update, and can I change it manually without issues?
The ruby binary that is found at /usr/bin/ruby is the version of Ruby installed by MacOS and should be left alone. Homebrew, Chruby, RVM & RBEnv all will install rubies in different locations away from the base so that they don't overwrite it or change it. This is expected behaviour, as you don't know what could be depending on the system ruby, or what has been natively compiled against it.
I am a new bee with sinatra and i am not an expert with ruby management tools like rvm and rbenv and i have the following issue: When i run a bundle install in my app, gems are installed and i have the following response "Bundled gems are installed into ./vendor/bundle." But when i try to run my sinatra app, it is displayed that i dont have sinatra installed and when i try this command line "gem list", i dont it found too.
I am using rbenv, and i dont have a clue how to resolve that. When i install gem by gem like "gem install sinatra" it works fine, but it's really painful, so my question is how to resolve that ?
PS: i tried to manage my ruby manager with rvm but i had issues so i moved to rbenv, maybe this is all about the path where gems are installed
This is a print of my gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.1
- RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin15]
- INSTALLATION DIRECTORY: /Users/laadhari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- USER INSTALLATION DIRECTORY: /Users/laadhari/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/laadhari/.rbenv/versions/2.3.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/laadhari/.rbenv/versions/2.3.1/bin
- SPEC CACHE DIRECTORY: /Users/laadhari/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/laadhari/.rbenv/versions/2.3.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /Users/laadhari/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- /Users/laadhari/.gem/ruby/2.3.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/laadhari/.rbenv/versions/2.3.1/bin
- /usr/local/Cellar/rbenv/1.0.0/libexec
- /Users/laadhari/.rbenv/shims
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
A print of my Gemfile
source 'https://rubygems.org'
gem 'sinatra', '~> 1.4.7'
gem "sinatra-activerecord"
gem 'mysql2'
gem 'rest-client'
gem 'thin'
gem 'rake'
when i run :
gem list
*** LOCAL GEMS ***
...
After successfully running bundle install, I dont find gems from Gemfile in the local gems...
One of the objectives of Bundler is to not pollute the global Gem list. This is achieved by NOT installing the bundled gems to the default location.
So to make sure your app finds the bundled gems, you have a few options:
Using bundle exec
When starting your application (ie. using rackup or ruby ./app.rb), prefix the command with bundle exec
bundle exec rackup
#=> Thin web server (v1.7.0 codename Dunder Mifflin)
#=> Maximum connections set to 1024
#=> Listening on localhost:9292, CTRL+C to stop
#=> ...
More Info: https://bundler.io/v1.12/man/bundle-exec.1.html
Using Bundler.setup
Before loading your dependencies (with require), load Bunder:
require 'rubygems'
require 'bundler/setup'
# require your gems as usual
require 'sinatra'
More info: https://bundler.io/v1.12/bundler_setup.html
Source & Further reading
I strongly suggest to read the excellent documentation at https://bundler.io/v1.12/#getting-started .
One more thing, to find out WHERE your bundled gems actually are installed, run the following command:
bundle config path
#=> Settings for `path` in order of priority. The top value will be used
#=> Set for your local app (/path/to/project/.bundle/config): ".bundle"
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.
I can finds gems that are installed using gem list, but it doesn't show me where the gems are installed.
How can I find where the gems are, and how can I know before installing a gem where it will be installed?
Use gem environment to find out about your gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 2.1.5
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-darwin12.4.0]
- INSTALLATION DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0
- RUBY EXECUTABLE: /Users/ttm/.rbenv/versions/2.0.0-p247/bin/ruby
- EXECUTABLE DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/bin
- SPEC CACHE DIRECTORY: /Users/ttm/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-12
- GEM PATHS:
- /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0
- /Users/ttm/.gem/ruby/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/ttm/.rbenv/versions/2.0.0-p247/bin
- /Users/ttm/.rbenv/libexec
- /Users/ttm/.rbenv/plugins/ruby-build/bin
- /Users/ttm/perl5/perlbrew/bin
- /Users/ttm/perl5/perlbrew/perls/perl-5.18.1/bin
- /Users/ttm/.pyenv/shims
- /Users/ttm/.pyenv/bin
- /Users/ttm/.rbenv/shims
- /Users/ttm/.rbenv/bin
- /Users/ttm/bin
- /usr/local/mysql-5.6.12-osx10.7-x86_64/bin
- /Users/ttm/libsmi/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/bin
Notice the two sections for:
INSTALLATION DIRECTORY
GEM PATHS
I found it useful to get a location of the library file with:
gem which *gemname*
After installing the gems, if you want to know where a particular gem is. Try typing:
gem list
You will be able to see the list of gems you have installed. Now use bundle show and name the gem you want to know the path for, like this:
bundle show <gemName>
Or (as of younger versions of bundler):
bundle info <gemName>
To complete other answers, the gem-path gem can find the installation path of a particular gem.
Installation:
gem install gem-path
Usage:
gem path rails
=> /home/cbliard/.rvm/gems/ruby-2.1.5/gems/rails-4.0.13
gem path rails '< 4'
=> /home/cbliard/.rvm/gems/ruby-2.1.5/gems/rails-3.2.21
This is really handy as you can use it to grep or edit files:
grep -R 'Internal server error' "$(gem path thin)"
subl "$(gem path thin)"
You can check it from your command prompt by running gem help commands and then selecting the proper command:
kirti#kirti-Aspire-5733Z:~$ gem help commands
GEM commands are:
build Build a gem from a gemspec
cert Manage RubyGems certificates and signing settings
check Check a gem repository for added or missing files
cleanup Clean up old versions of installed gems in the local
repository
contents Display the contents of the installed gems
dependency Show the dependencies of an installed gem
environment Display information about the RubyGems environment
fetch Download a gem and place it in the current directory
generate_index Generates the index files for a gem server directory
help Provide help on the 'gem' command
install Install a gem into the local repository
list Display gems whose name starts with STRING
lock Generate a lockdown list of gems
mirror Mirror all gem files (requires rubygems-mirror)
outdated Display all gems that need updates
owner Manage gem owners on RubyGems.org.
pristine Restores installed gems to pristine condition from
files located in the gem cache
push Push a gem up to RubyGems.org
query Query gem information in local or remote repositories
rdoc Generates RDoc for pre-installed gems
regenerate_binstubs Re run generation of executable wrappers for gems.
search Display all gems whose name contains STRING
server Documentation and gem repository HTTP server
sources Manage the sources and cache file RubyGems uses to
search for gems
specification Display gem specification (in yaml)
stale List gems along with access times
uninstall Uninstall gems from the local repository
unpack Unpack an installed gem to the current directory
update Update installed gems to the latest version
which Find the location of a library file you can require
yank Remove a specific gem version release from
RubyGems.org
For help on a particular command, use 'gem help COMMAND'.
Commands may be abbreviated, so long as they are unambiguous.
e.g. 'gem i rake' is short for 'gem install rake'.
kirti#kirti-Aspire-5733Z:~$
Now from the above I can see the command environment is helpful. So I would do:
kirti#kirti-Aspire-5733Z:~$ gem help environment
Usage: gem environment [arg] [options]
Common Options:
-h, --help Get help on this command
-V, --[no-]verbose Set the verbose level of output
-q, --quiet Silence commands
--config-file FILE Use this config file instead of default
--backtrace Show stack backtrace on errors
--debug Turn on Ruby debugging
Arguments:
packageversion display the package version
gemdir display the path where gems are installed
gempath display path used to search for gems
version display the gem format version
remotesources display the remote gem servers
platform display the supported gem platforms
<omitted> display everything
Summary:
Display information about the RubyGems environment
Description:
The RubyGems environment can be controlled through command line arguments,
gemrc files, environment variables and built-in defaults.
Command line argument defaults and some RubyGems defaults can be set in a
~/.gemrc file for individual users and a /etc/gemrc for all users. These
files are YAML files with the following YAML keys:
:sources: A YAML array of remote gem repositories to install gems from
:verbose: Verbosity of the gem command. false, true, and :really are the
levels
:update_sources: Enable/disable automatic updating of repository metadata
:backtrace: Print backtrace when RubyGems encounters an error
:gempath: The paths in which to look for gems
:disable_default_gem_server: Force specification of gem server host on
push
<gem_command>: A string containing arguments for the specified gem command
Example:
:verbose: false
install: --no-wrappers
update: --no-wrappers
:disable_default_gem_server: true
RubyGems' default local repository can be overridden with the GEM_PATH and
GEM_HOME environment variables. GEM_HOME sets the default repository to
install into. GEM_PATH allows multiple local repositories to be searched for
gems.
If you are behind a proxy server, RubyGems uses the HTTP_PROXY,
HTTP_PROXY_USER and HTTP_PROXY_PASS environment variables to discover the
proxy server.
If you would like to push gems to a private gem server the RUBYGEMS_HOST
environment variable can be set to the URI for that server.
If you are packaging RubyGems all of RubyGems' defaults are in
lib/rubygems/defaults.rb. You may override these in
lib/rubygems/defaults/operating_system.rb
kirti#kirti-Aspire-5733Z:~$
Finally to show you what you asked, I would do:
kirti#kirti-Aspire-5733Z:~$ gem environment gemdir
/home/kirti/.rvm/gems/ruby-2.0.0-p0
kirti#kirti-Aspire-5733Z:~$ gem environment gempath
/home/kirti/.rvm/gems/ruby-2.0.0-p0:/home/kirti/.rvm/gems/ruby-2.0.0-p0#global
kirti#kirti-Aspire-5733Z:~$
You can trick gem open into displaying the gem path:
VISUAL=echo gem open gem-name
Example:
VISUAL=echo gem open rails
=> /usr/local/opt/asdf/installs/ruby/2.4.3/lib/ruby/gems/2.4.0/gems/rails-5.1.4
It just works, and no third party gem is necessary.
gem env works just like gem environment. Saves some typing.
# gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14
- RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [i686-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.0.0
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.0.0
- /root/.gem/ruby/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
The gem env lists where gems can be installed, but this can be 10 or more locations. If you want to know where a particular gem is installed, you can execute:
gem list -d <gemname>
Example output:
tilt (2.0.9)
Author: Ryan Tomayko
Homepage: http://github.com/rtomayko/tilt/
License: MIT
Installed at: /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0
Generic interface to multiple Ruby template engines
if you are using rvm tool you can run this command to print gem path:
rvm gemdir
OR
echo $GEM_HOME
This works and gives you the installed at path for each gem. This super helpful when trying to do multi-stage docker builds.. You can copy in the specific directory post-bundle install.
bash-4.4# gem list -d
Output::
aasm (5.0.6)
Authors: Thorsten Boettger, Anil Maurya
Homepage: https://github.com/aasm/aasm
License: MIT
Installed at: /usr/local/bundle
State machine mixin for Ruby objects
One can go to rails console and do
Gem.bin_path('<gem-name>', '<gem-executable-name>')
It returns exact path to the gem file executable.
Ref: https://www.rubydoc.info/github/rubygems/rubygems/Gem.bin_path
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.