我试图使用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
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
你没有写/Library/Ruby/Gems/1.8目录的权限。
也就是说,你没有权限在那里写东西。
这是苹果安装的Ruby版本,供他们自己使用。虽然如果您知道自己在做什么,可以对其进行一些小的修改,因为您不确定权限问题,但我认为继续这样做并不是个好主意。
相反,我强烈建议您考虑使用rbenv或RVM来管理一个单独的Ruby,将其安装到您的主目录中的沙箱中,这样您就可以修改/折叠/主轴/更改,而不必担心会弄乱系统Ruby。
在这两者之间,我使用rbenv,尽管我过去经常使用RVM。rbenv采用了一种更加“不干涉”的方法来管理Ruby安装。RVM有很多特性并且非常强大,但是,结果是更具有侵入性。无论哪种情况,在开始安装之前,都要多阅读几次安装文档。
有两种路由:使用rbenv或RVM。下面是这两种食物的食谱。在此之前,您可能希望关闭gem本地文档的安装。
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
然后:
安装rbenv
安装ruby-build
运行:
rbenv install 2.1.2 (or whatever version you prefer)
rbenv global 2.1.2
gem update --system
这将在本地目录中安装gem系统的最新版本。这意味着您不会干扰系统配置。如果您正在问这个问题,那么您不应该破坏系统安全性,并且您将花费更长的时间来了解可能遇到的问题,而不仅仅是找到一种简单的方法来避免您开始时遇到的问题。了解更多关于操作系统和编程的知识后,再学习InfoSec。
使用'RVM'替代:
rvm install 2.1.2
rvm use 2.1.2
gem update --system
这有同样的结果,您最终得到的是一个本地Ruby和Gem系统,它不会影响系统版本。不需要Homebrew,也不需要覆盖系统库等等。