问题描述
我一直在使用 rubygems 和 rvm,它运行得非常好,但是现在当我尝试安装 gem 时出现错误
I was messing around with rubygems and rvm and it was working perfectly fine but now when I try to install a gem I get an error
gem install railsERROR: While执行 gem ... (Errno::EACCES)权限被拒绝 -/Users/da/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.11/.gitignore
当我执行 sudo 时它可以工作,但我以前从来不需要这样做来安装 gem.
It works when I do sudo, but I never had to do this before to install a gem.
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.6.2
- RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [x86_64-darwin10.7.0]
- INSTALLATION DIRECTORY: /Users/da/.rvm/gems/ruby-1.9.2-p180
- RUBY EXECUTABLE: /Users/da/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
- EXECUTABLE DIRECTORY: /Users/da/.rvm/gems/ruby-1.9.2-p180/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-10
- GEM PATHS:
- /Users/da/.rvm/gems/ruby-1.9.2-p180
- /Users/da/.rvm/gems/ruby-1.9.2-p180@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
$ sudo gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.6.2
- RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [x86_64-darwin10.7.0]
- INSTALLATION DIRECTORY: /Users/da/.rvm/gems/ruby-1.9.2-p180
- RUBY EXECUTABLE: /Users/danest/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
- EXECUTABLE DIRECTORY: /Users/da/.rvm/gems/ruby-1.9.2-p180/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-10
- GEM PATHS:
- /Users/da/.rvm/gems/ruby-1.9.2-p180
- /Users/da/.rvm/gems/ruby-1.9.2-p180@global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
推荐答案
您似乎已将 root 用户设置为使用您的主文件夹中的 rvm install.这意味着当您使用 sudo 安装 gem 时,文件将属于 root.因此,当您尝试安装 gem 时,会遇到权限错误.
It looks like you've set the root user to use the rvm install which is in your home folder. This means when you install a gem with sudo, the files will belong to root. So, when you try and install a gem as you, you're getting permission errors.
要修复,您需要将 rvm 文件夹返回给您(我假设,根据您的文件路径,您的用户名是da")...
To fix, you need to chown the rvm folder back to you (I'm assuming, from your file paths, that your username is 'da' here)...
sudo chown -R da:da /Users/da/.rvm
为了避免将来发生这种情况,我建议将 root 的路径设置为它自己安装的 rvm 或系统 gems.
To avoid this happening in the future, I'd recommend setting root's path to be either its own install of rvm, or system gems.
这篇关于rvm gem 安装错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!