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
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 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"
I have installed the rubygems-mirror gem (successfully it would seem), but when I execute the gem I get the following error:
$ gem mirror
ERROR: Install the rubygems-mirror gem for the mirror command
EDIT: The installation was done using a gem install command, and I have setup the ~/.gem/.mirrorrc file as a cut/paste from the gem documentation, save the target directory.
Both doing an listing of ~/.gems/ruby/gems and running gem list show I have rubygems-mirror version 1.1.0 on my system. Here is my gem list:
$ gem list rubygems-mirror
*** LOCAL GEMS ***
rubygems-mirror (1.1.0)
$ ls ~/.gem/ruby/gems/rubygems-mirror-1.1.0
CHANGELOG.rdoc lib Manifest.txt Rakefile README.rdoc test
And here is my gem environment:
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14
- RUBY VERSION: 2.0.0 (2014-11-13 patchlevel 598) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/localadm/.gem/ruby
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /home/localadm/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/localadm/.gem/ruby
- /usr/share/gems
- /usr/local/share/gems
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
I've never had such an issue with a gem before, I'm a little confused at what to do here. To make things even more confusing, I can run gem mirror --help and receive the correct help text for the mirror gem as output.
UPDATE: It seems I am able to use a work-around. I have cloned the git source repo, and seem to be able to execute $ rake mirror:update successfully. I'm sitting at about 2000/819236 gems downloaded, but so far so good.
Still would like to figure out how I can run the mirror simply with $ gem mirror as it should work.
I manually built Ruby 1.9.2 on Snow Leopard. Now I can’t find my old GEM files. I’m guessing they're in a different path now or something. So I have three questions:
What is the "old" gem path, where gem install sinatra puts the sinatra gem?
What is the "new" gem path, which is set when I build Ruby manually?
How do I change it so Ruby finds my gems again?
Typing gem env (Using your old Ruby install's gem command) at a command prompt gives something similar to:
> RubyGems Environment:
> - RUBYGEMS VERSION: 1.3.6
> - RUBY VERSION: 1.9.1 (2009-07-16 patchlevel 243) [i386-mingw32]
> - INSTALLATION DIRECTORY: C:/Ruby19/lib/ruby/gems/1.9.1
> - RUBY EXECUTABLE: C:/Ruby19/bin/ruby.exe
> - EXECUTABLE DIRECTORY: C:/Ruby19/bin
> - RUBYGEMS PLATFORMS:
> - ruby
> - x86-mingw32
> - GEM PATHS:
> - C:/Ruby19/lib/ruby/gems/1.9.1
> - C:/Users/Username/.gem/ruby/1.9.1
> - GEM CONFIGURATION:
> - :update_sources => true
> - :verbose => true
> - :benchmark => false
> - :backtrace => false
> - :bulk_threshold => 1000
> - REMOTE SOURCES:
> - http://rubygems.org/
(On Windows... I imagine Snow Leopard will have a similar format)
The GEM PATHS field is the interesting thing here. If you go to those directories listed, you should see a folder named cache. That will contain a list of .gem files corresponding to all the installed gems in that specific directory. You should just be able to call gem install *gemname* on each of those gem files (using your new Ruby install's gem command).
EDIT: Mistakenly referred to INSTALLATION DIRECTORY instead of GEM PATHS. Greg reminded me that there are multiple locations known by a specific installation of Rubygems. All of those locations needs to be checked for gems used by that installation of Ruby.
Your "old" gems would be relative to the Ruby that came bundled with the Mac because the gem command is included with Ruby 1.8.7, which is stock on Snow Leopard. If your which ruby shows /usr/bin/ruby, your gem environments should be similar to:
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/greg/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
If you are using RVM you might be able to tell it to copy your gems from the system gemset to one under RVM's control. I haven't tried doing that as I install RVM immediately and let it handle all my Ruby installation and then I ignore the system's installation.
If your which ruby shows /usr/local/bin/ruby then the gem env command should reflect the changed path for the version you compiled from source.
I'm curious WHY you would build it manually, when RVM is available to handle all the configuration and installation, and largely remove any concerns about where things are and whether you've just stomped on the system's installed version.
When RVM has installed a Ruby version, it will all be in ~/.rvm and your Gems will be nicely located there too. You'll be able to manage the gems as gemsets, relative to each version of Ruby, and switch back and forth instantly. Or, even better, you can run a command/program in each version of Ruby you have installed to test them using rvm ruby 'some command'.
Notice in the above gem env output that gems are in three separate areas on the disk. Under RVM's control they're in RVM's sandbox:
- GEM PATHS:
- /Users/greg/.rvm/gems/ruby-1.9.2-p0
- /Users/greg/.rvm/gems/ruby-1.9.2-p0#global
That makes it trivial for me to back them up, or blow them away if I want to.
I used to compile my rubies from source on my Macs and Linux boxes. I use RVM for that now. It's so much better than doing it by hand.
I believe the standard gem install path on OS X is:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/
I'm running Ubuntu 10.04 and originally installed ruby 1.9.1 (from source). I've just decided to try out ruby 1.9.2 and rails 3, and it seemed like a good time to use rvm to deal with the multiple ruby installs and gemsets.
rvm installed and seems to be working, I installed ruby 1.9.2 in rvm and made that my default ruby. However, every time I try to install a gem under ruby 1.9.2 I see this error.
mark#Steve-Austins-Penguin:~$ gem install haml
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /home/mark/.gem/specs
gem environment returns:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/mark/.rvm/gems/ruby-1.9.2-p0
- RUBY EXECUTABLE: /home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
- EXECUTABLE DIRECTORY: /home/mark/.rvm/gems/ruby-1.9.2-p0/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/mark/.rvm/gems/ruby-1.9.2-p0
- /home/mark/.rvm/gems/ruby-1.9.2-p0#global
<snip>
But if the correct installation, ruby and gem paths are showing here why is ruby trying to install gems to /home/mark/.gem? All the variables and paths shown by env look right, and I can't find a .gemrc file anywhere on my system that might contain conflicting path settings.
So I guess my question is what might be causing rubygems to attempt to install to /home/mark/.gems instead of the correct paths set by rvm?
In response to the question below:
mark#Steve-Austins-Penguin:~$ echo $PATH
/home/mark/.rvm/gems/ruby-1.9.2-p0/bin:/home/mark/.rvm/gems/ruby-1.9.2-p0#global/bin:/home/mark/.rvm/rubies/ruby-1.9.2-p0/bin:/home/mark/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
mark#Steve-Austins-Penguin:~$ which gem
/home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/gem
mark#Steve-Austins-Penguin:~$ rvm list
rvm rubies
ruby-1.8.7-p302 [ x86_64 ]
=> ruby-1.9.2-p0 [ x86_64 ]
mark#Steve-Austins-Penguin:~$ env
rvm_gemsets_path=/home/mark/.rvm/gemsets
MANPATH=:/home/mark/.rvm/man
rvm_scripts_path=/home/mark/.rvm/scripts
rvm_bin_path=/home/mark/.rvm/bin
GEM_HOME=/home/mark/.rvm/gems/ruby-1.9.2-p0
rvm_patchsets_path=/home/mark/.rvm/patchsets
SHELL=/bin/bash
IRBRC=/home/mark/.rvm/rubies/ruby-1.9.2-p0/.irbrc
rvm_patches_path=/home/mark/.rvm/patches
MY_RUBY_HOME=/home/mark/.rvm/rubies/ruby-1.9.2-p0
rvm_selfcontained=1
USER=mark
__shell_array_start=0
rvm_gems_cache_path=/home/mark/.rvm/gems/cache
rvm_config_path=/home/mark/.rvm/config
rvm_path=/home/mark/.rvm
USERNAME=mark
rvm_gemset_separator=#
rvm_ruby_args=
rvm_rubies_path=/home/mark/.rvm/rubies
PWD=/home/mark
rvm_hooks_path=/home/mark/.rvm/hooks
rvm_version=1.0.1
rvm_src_path=/home/mark/.rvm/src
HOME=/home/mark
rvm_gems_path=/home/mark/.rvm/gems
rvm_ruby_string=ruby-1.9.2-p0
BUNDLE_PATH=/home/mark/.rvm/gems/ruby-1.9.2-p0
rvm_tmp_path=/home/mark/.rvm/tmp
LOGNAME=mark
GEM_PATH=/home/mark/.rvm/gems/ruby-1.9.2-p0:/home/mark/.rvm/gems/ruby-1.9.2-p0#global
rvm_action=list
rvm_log_path=/home/mark/.rvm/log
rvm_interactive=1
RUBY_VERSION=ruby-1.9.2-p0
rvm_archives_path=/home/mark/.rvm/archives
rvm_repo_path=/home/mark/.rvm/repos
_=/usr/bin/env
Note that I've edited down the response from env slightly - simply to keep the size of this post under control - by removing all the entries relating to X, GNOME and SSH.
Following up the backtrace from running gem install -V --backtrace --debug haml (thanks zzzhc) and taking a closer look at the /home/mark/.gem directory I found that there were no gems installed there, just gemspec files and gem source files. In the spirit of experimentation I deleted /home/mark/.gem and re ran the gem install command and suddenly it was working. And that it had recreated /home/mark/.gem containing gemspecs for the gems I'd just installed.
It's clear now that I'd misinterpreted the error message in the original question; rubygems didn't fail while trying to install gems to /home/mark/.gem, it was simply using that directory as a temporary store for the gemspecs of newly downloaded gems about to be installed. Before installing rvm I'd been installing gems onto the system using sudo gem install... which would have created the /home/mark/.gem directory with root permissions. So rubygems run without sudo was unable to access the temp directory to store gemspecs in and was aborting before it could install the gems. Doh!
Another way is type which gem after getting into the ruby version. You will get something like this - /home/username/.rvm/rubies/ruby-1.9.2-p180/bin/gem. Now just type sudo /home/username/.rvm/rubies/ruby-1.9.2-p180/bin/gem install gem_name.
Specifying the complete path and adding sudo work fine.
check the first line of /home/mark/.rvm/rubies/ruby-1.9.2-p0/bin/gem and look at http://yehudakatz.com/2010/08/24/a-tale-of-abort-traps-or-always-question-your-assumptions/