我试图使用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.
有人知道怎么解决这个问题吗?
当前回答
该错误的原因是您没有以root用户登录终端。
如果你已经在终端类型的mac上启用了根用户
$ su
如果您没有root用户,您需要使用以下步骤启用它
From the Apple menu choose System Preferences…. From the View menu choose Users & Groups. Click the lock and authenticate as an administrator account. Click Login Options…. Click the “Edit…” or “Join…” button at the bottom right. Click the “Open Directory Utility…” button. Click the lock in the Directory Utility window. Enter an administrator account name and password, then click OK. Choose Enable Root User from the Edit menu. Enter the root password you wish to use in both the Password and Verify fields, then click OK.
更多内容请登录http://support.apple.com/kb/ht1528
在被困了几个小时后,至少它对我有用。
其他回答
正如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...
2021年方案(使用rvm):
如果您在终端中输入哪种ruby,并显示/usr/bin/ruby,您可以尝试此解决方案。
安装区 curl -L https://get.rvm.io | bash -s稳定 使用RVM安装ruby RVM安装ruby-3.0.0 使用您安装的ruby版本 RVM使用ruby-3.0.0 再次输入哪个ruby,这将显示/Users/mac_user_name/.rvm/ ruby /ruby-3.0.0/bin/ruby。 这是使用ruby的新途径。
你需要修正你的路径。
要确定此修复是否有效,请运行以下命令:
which gem
这应该会输出一个你没有权限的目录:
/usr/bin/gem
要修复此问题,请执行以下步骤:
Determine the path you need to copy to your profile: rbenv init - The first line of the output is the line you need to copy over to your profile: export PATH="/Users/justin/.rbenv/shims:${PATH}" #path that needs to be copied source "/usr/local/Cellar/rbenv/0.4.0/libexec/../completions/rbenv.zsh" rbenv rehash 2>/dev/null rbenv() { typeset command command="$1" if [ "$#" -gt 0 ]; then shift fi case "$command" in rehash|shell) eval `rbenv "sh-$command" "$@"`;; *) command rbenv "$command" "$@";; esac } Copy the path to your profile and save it. Reload your profile (source ~/.zshenv for me). Run rbenv rehash.
现在当你运行哪个gem时,你应该得到一个你有权限的本地路径:
/Users/justin/.rbenv/shims/gem
这将以一种干净的方式修复MacOS Mojave和Catalina的问题:
brew install ruby
然后将GEM_HOME设置为您的用户目录。终端:
Bash: echo '#安装Ruby Gems到~/ Gems ' >> ~/.bashrc echo 'export GEM_HOME=$HOME/gems' >> ~/.bashrc echo 'export PATH=$HOME/gems/bin:$PATH' >> ~/.bashrc . txt 源~ / . bashrc 如果在Zsh上: echo '#安装Ruby Gems到~/ Gems ' >> ~/.zshrc echo 'export GEM_HOME=$HOME/gems' >> ~/.zshrc echo 'export PATH=$HOME/gems/bin:$PATH' >> ~/.zshrc . txt 源~ / . zshrc
为我工作:
sudo gem uninstall cocoapods
sudo gem install cocoapods