Why do “gem” and “sudo gem” have different installation directories?

拜拜、爱过 提交于 2019-11-29 15:52:29

问题


I remember I used gem install rails to install Rails, but today when I want to install another gem, by typing

gem install ruby-recaptcha

it fails, saying:

You don't have write permissions into the ...

Then I found my gem environment and sudo gem environment have different results:

For gem environment:

RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.15
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.0.1]
  - INSTALLATION DIRECTORY: /Users/hx/.rvm/gems/ruby-1.9.2-p290
  - RUBY EXECUTABLE: /Users/hx/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/hx/.rvm/gems/ruby-1.9.2-p290/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/hx/.rvm/gems/ruby-1.9.2-p290
     - /Users/hx/.rvm/gems/ruby-1.9.2-p290@global
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :gempath => ["/Users/hx/.rvm/gems/ruby-1.9.2-p290"]
     - :sources => ["http://rubygems.org/"]
  - REMOTE SOURCES:
     - http://rubygems.org/

For sudo gem environment:

  - RUBYGEMS VERSION: 1.8.15
  - RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.0.1]
  - INSTALLATION DIRECTORY: /Users/hx/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1
  - RUBY EXECUTABLE: /Users/hx/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/hx/.rvm/rubies/ruby-1.9.2-p290/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-11
  - GEM PATHS:
     - /Users/hx/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/gems/1.9.1
     - /Users/hx/.gem/ruby/1.9.1
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - :gempath => ["/Users/hx/.rvm/gems/ruby-1.9.2-p290"]
     - :sources => ["http://rubygems.org/"]
  - REMOTE SOURCES:
     - http://rubygems.org/

Noticed that the installation directory is different. So when I use gem, I do not have permissions (I don't know why I suddenly lose the permission). But when I use sudo gem, the gem is not installed into the right place. How can I fix this?


回答1:


RVM uses environment variables to configure rubygems - the gem command, basically if you have user installation (~/.rvm) you should not need to use to call any commands with sudo, especially gem - that if worked would install rail as root user in your home directory, making it impossible for you to manage your files ... if you have any good reasons to use sudo - use rvmsudo instead - but really you should not have that need, especially to install gems.

If you want to have some commands available in your system (like gist) you can use rvm wrapper and link generated binary in /usr/bin

to fix permissions in your home:

sudo chown $USER: ~/.rvm
sudo chmod u+rw ~/.rvm


来源:https://stackoverflow.com/questions/9065496/why-do-gem-and-sudo-gem-have-different-installation-directories

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!