我试图使用gem install mygem或使用gem update——system更新RubyGems安装一个gem,它失败了,错误如下:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
有人知道怎么解决这个问题吗?
我试图使用gem install mygem或使用gem update——system更新RubyGems安装一个gem,它失败了,错误如下:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
有人知道怎么解决这个问题吗?
当前回答
我对我的Mac进行了格式化,许多建议的解决方案对我不起作用。 对我来说有用的是这些正确顺序的命令:
安装自制程序: /usr/bin/ruby -e "$(curl - ssl https://raw.githubusercontent.com/Homebrew/install/master/install)" 安装Ruby: 编译安装ruby 安装指南: 须藤宝石安装指南针
其他回答
sudo gem update --system
sudo gem install (gemfile)
你为什么不这样做:
sudo gem update --system
我需要做一个rbenv rehash,这样它就会指向我的本地Gem库。
看起来您已经让您的gem管理器指向系统库,因此,与其混淆权限,不如为您的管理器执行等效的“rehash”以获得指向本地的内容。
正如bobbdelsol所指出的,rehash对我来说很管用:
==> which ruby
/usr/bin/ruby
==> rbenv install 1.9.3-p551
Downloading ruby-1.9.3-p551.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p551.tar.bz2
Installing ruby-1.9.3-p551...
Installed ruby-1.9.3-p551 to /Users/username/.rbenv/versions/1.9.3-p551
==> which ruby
/Users/username/.rbenv/shims/ruby
==> which gem
/Users/username/.rbenv/shims/gem
==> gem install compass
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
==> ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
==> rbenv global 1.9.3-p551
==> ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
==> rbenv global 1.9.3-p551
==> rbenv rehash
==> ruby -v
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-darwin15.4.0]
==> gem install compass
Fetching: sass-3.4.22.gem (100%)
Fetching: multi_json-1.11.3.gem (100%)
Fetching: compass-core-1.0.3.gem (100%)
Fetching: compass-import-once-1.0.5.gem (100%)
Fetching: chunky_png-1.3.5.gem (100%)
Fetching: rb-fsevent-0.9.7.gem (100%)
Fetching: ffi-1.9.10.gem (100%)
Building native extensions. This could take a while...
Fetching: rb-inotify-0.9.7.gem (100%)
Fetching: compass-1.0.3.gem (100%)
Compass is charityware. If you love it, please donate on our behalf at http://umdf.org/compass Thanks!
Successfully installed sass-3.4.22
Successfully installed multi_json-1.11.3
Successfully installed compass-core-1.0.3
Successfully installed compass-import-once-1.0.5
Successfully installed chunky_png-1.3.5
Successfully installed rb-fsevent-0.9.7
Successfully installed ffi-1.9.10
Successfully installed rb-inotify-0.9.7
Successfully installed compass-1.0.3
9 gems installed
Installing ri documentation for sass-3.4.22...
Installing ri documentation for multi_json-1.11.3...
Installing ri documentation for compass-core-1.0.3...
Installing ri documentation for compass-import-once-1.0.5...
Installing ri documentation for chunky_png-1.3.5...
Installing ri documentation for rb-fsevent-0.9.7...
Installing ri documentation for ffi-1.9.10...
Installing ri documentation for rb-inotify-0.9.7...
Installing ri documentation for compass-1.0.3...
Installing RDoc documentation for sass-3.4.22...
Installing RDoc documentation for multi_json-1.11.3...
Installing RDoc documentation for compass-core-1.0.3...
Installing RDoc documentation for compass-import-once-1.0.5...
Installing RDoc documentation for chunky_png-1.3.5...
Installing RDoc documentation for rb-fsevent-0.9.7...
Installing RDoc documentation for ffi-1.9.10...
Installing RDoc documentation for rb-inotify-0.9.7...
Installing RDoc documentation for compass-1.0.3...
您确实应该使用Ruby版本管理器。
在执行gem更新命令时,正确使用它可以防止并解决权限问题。
我推荐rbenv。
但是,即使使用Ruby版本管理器,仍然可能会得到相同的错误消息。
如果这样做,并且使用的是rbenv,只需验证~/。rbenv/shims目录在系统Ruby路径之前。
$ echo $PATH将显示加载路径的顺序。
如果您发现shims目录位于系统Ruby bin目录之后,则编辑~/。export PATH=$HOME/.rbenv/shims:$PATH . bashrc文件,并将其作为最后一个导出PATH命令
$ ruby -v显示你正在使用的ruby版本
这表明我目前使用的是Ruby的系统版本(通常不太好)
$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]
$ rbenv global 1.9.3-p448将我切换到更新的预安装版本(参见下面的参考资料)。
这表明我正在使用一个更新版本的Ruby(这可能不会导致Gem::FilePermissionError)
$ ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-darwin12.4.0]
通常不需要在gem命令前加上sudo。如果您觉得需要这样做,则可能是配置错误。
关于rbenv的详细信息请参见:
https://github.com/sstephenson/rbenv http://robots.thoughtbot.com/post/47273164981/using-rbenv-to-manage-rubies-and-gems