开发者

ruby gems under rvm on Ubuntu (failing to) install in the wrong location

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? A开发者_开发百科ll 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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜