我试图使用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.
有人知道怎么解决这个问题吗?
当前回答
你需要修正你的路径。
要确定此修复是否有效,请运行以下命令:
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
其他回答
安装rbenv;
然后在~/的末尾加上eval "$(rbenv init -)"。Bash_profile(或~/.zshrc MacOS);
打开一个新终端,运行gem install ***将工作!
给用户$whoami在这些文件夹中创建一些东西
sudo chown -R user /Library/Ruby/Gems/2.0.0
您可以更改GEM_HOME。您还在您的主目录下有一个gem文件夹来检查它的使用
$ gem env
结果如下。不相关的部分省略。
...
- GEM PATHS:
- /Users/xxx/.gem/ruby/2.6.0
- /Library/Ruby/Gems/2.6.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0
...
你可以使用你的/Users/xxx/.gem/ruby/2.6.0文件夹。
vim ~/.bash_profile
添加以下行
export GEM_HOME=~/.gem/ruby/2.6.0/
之后你就可以使用了
source ~/.bash_profile
cd /图书馆/ Ruby /珠宝/ 2.0.0
开放。
右击获取信息
点击锁定
地方的密码
让一切都能读能写。
这将以一种干净的方式修复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