您没有/Library/Ruby/Gems/2.3.0 目录的写权限.(mac 用户) [英] You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user)

查看:84
本文介绍了您没有/Library/Ruby/Gems/2.3.0 目录的写权限.(mac 用户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我需要做的.

要运行规范,您需要安装 RSpec.首先,在项目的根目录中运行 gem install bundler.然后,运行 bundle install.要运行单个规范文件,请运行如下命令:bundle exec rspec spec/00_hello_spec.rb.要一次运行所有规范,请运行 bundle exec rspec.

To run the specs, you'll need to install RSpec. First, run gem install bundler in the root directory of your project. Then, run bundle install. To run a single spec file, run a command like this: bundle exec rspec spec/00_hello_spec.rb. To run all of the specs at once, run bundle exec rspec.

所以,我在终端中输入了 gem install bundler,然后得到了错误:

So, I typed gem install bundler in Terminal, and got the error:

您没有/Library/Ruby/Gems/2.3.0 目录的写权限.

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

这是在 atom 的项目文件中

and this was in the project file in atom

source "https://rubygems.org"
gem "rspec", "~> 3.2.0"

我的问题是:

似乎终端给了我响应,因为我不应该更改 ruby​​ 上的任何内容,我需要在 atom 内部 bundle install ?谁能告诉我如何使用 atom 或在 atom 中运行任何东西?

It seems like terminal is giving me the response because I'm not supposed to change anything on ruby, and I need to bundle install inside of atom? Could anyone tell me how to use atom or run anything in atom?

推荐答案

更新:

  • I now have a very detailed step-by-step tutorial for setting up a proper Ruby development environment on a Mac, including a Homebrew troubleshooting section with the most common issues people run into.
  • Although my step-by-step tutorial is guaranteed to work, I also have a script that will save you a lot of time.
  • My tutorial uses a Ruby manager to install Ruby (chruby specifically) because that's the only way I recommend that you install Ruby. To learn more, read my guide that explains the various ways you can install Ruby gems on a Mac.

您是对的,macOS 不允许您对 Mac 随附的 Ruby 版本进行任何更改.但是,可以使用独立版本的 Ruby 安装 bundler 之类的 gem,该版本不会干扰 Apple 提供的版本.

You are correct that macOS won't let you change anything with the Ruby version that comes installed with your Mac. However, it's possible to install gems like bundler using a separate version of Ruby that doesn't interfere with the one provided by Apple.

强烈建议不要使用 sudo 安装 gems 或更改系统文件和目录的权限,即使您知道自己在做什么.我们可以停止提供这种糟糕的建议吗?我写了一篇详细的文章,显示 为什么你不应该使用 sudo 来安装 gems.

Using sudo to install gems, or changing permissions of system files and directories is strongly discouraged, even if you know what you are doing. Can we please stop providing this bad advice? I wrote a detailed article that shows why you should never use sudo to install gems.

解决方案包括两个主要步骤:

The solution involves two main steps:

  1. 安装一个单独的 Ruby 版本,该版本不会干扰 Mac 附带的版本.
  2. 更新您的 PATH,使新 Ruby 版本的位置位于 PATH 的第一个位置.某些工具会自动为您执行此操作.如果您不熟悉 PATH 及其工作原理,它是您应该学习的基础知识之一,并且您将理解为什么有时会遇到未找到命令";错误以及如何修复它们.
  1. Install a separate version of Ruby that does not interfere with the one that came with your Mac.
  2. Update your PATH such that the location of the new Ruby version is first in the PATH. Some tools do this automatically for you. If you're not familiar with the PATH and how it works, it's one of the basics that you should learn, and you'll understand why you sometimes get "command not found" errors and how to fix them.

有多种方法可以在 Mac 上安装 Ruby.我推荐的最好方法是使用自动化脚本(就像我在上面编写并链接到的那个),它会为您设置合适的 Ruby 环境.这极大地减少了由于指令不充分而导致出错的机会,这些指令使用户手动执行大量操作,并让他们自行找出所有必要的步骤.

There are several ways to install Ruby on a Mac. The best way that I recommend, and that I wish was more prevalent in the various installation instructions out there, is to use an automated script (like the one I wrote and linked to above) that will set up a proper Ruby environment for you. This drastically reduces the chances of running into an error due to inadequate instructions that make the user do a bunch of stuff manually and leaving it up to them to figure out all the necessary steps.

您可以采取的另一条路线是花额外的时间手动完成所有工作,并希望一切顺利.首先,您需要安装 Homebrew,它会安装必备的命令行工具,并且可以轻松安装其他必要的工具.

The other route you can take is to spend extra time doing everything manually and hoping for the best. First, you will want to install Homebrew, which installs the prerequisite command line tools, and makes it easy to install other necessary tools.

然后,安装单独版本的 Ruby 的两种最简单方法是:

Then, the two easiest ways to install a separate version of Ruby are:

选择以下四个选项之一:

Choose one of these four options:

  • chrubyruby-install - 我的个人建议以及由我的脚本自动安装的建议.这些可以与 Homebrew 一起安装:
  • chruby and ruby-install - my personal recommendations and the ones that are automatically installed by my script. These can be installed with Homebrew:
brew install chruby ruby-install

  • rbenv - 可以与 Homebrew 一起安装

    • rbenv - can be installed with Homebrew

      RVM

      asdf

      如果你选择了 chrubyruby-install,你就可以像这样安装最新的 Ruby:

      If you chose chruby and ruby-install, you can then install the latest Ruby like this:

      ruby-install ruby
      

      根据上述工具的说明安装所有内容并配置.zshrc.bash_profile 后,退出并重新启动终端,然后切换到版本你想要的红宝石.对于 chruby,它会是这样的:

      Once you've installed everything and configured your .zshrc or .bash_profile according to the instructions from the tools above, quit and restart Terminal, then switch to the version of Ruby that you want. In the case of chruby, it would be something like this:

      chruby 3.0.1
      

      是否需要配置 .zshrc.bash_profile 取决于 您使用的是哪个 shell.

      Whether you need to configure .zshrc or .bash_profile depends on which shell you are using.

      • 使用 Homebrew 安装 ruby​​:
      brew install ruby
      

      然后通过运行以下命令更新您的 PATH:

      Then update your PATH by running this command:

      echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/2.7.0/bin:$PATH"' >> ~/.zshrc
      

      上述命令中的 2.7.0 假设 Homebrew 安装了以 2.7 开头的 Ruby 版本.如果您使用的是其他版本(您可以使用 ruby -v 进行检查),请将 2.7 替换为您的 Ruby 版本的前两位数字.

      The 2.7.0 in the command above assumes Homebrew installed a Ruby version that starts with 2.7. If you're using a different version (which you can check with ruby -v), replace 2.7 with the first two digits of your Ruby version.

      然后刷新"使这些更改生效的 shell:

      Then "refresh" your shell for these changes to take effect:

      source ~/.zshrc
      

      或者您可以打开一个新的终端选项卡,或者退出并重新启动终端.

      Or you can open a new terminal tab, or quit and restart Terminal.

      如果您使用 Bash,请将 .zshrc 替换为 .bash_profile.如果您不确定,请阅读我的指南以了解 您使用的是哪个 shell.

      Replace .zshrc with .bash_profile if you are using Bash. If you're not sure, read my guide to find out which shell you are using.

      要检查您现在是否使用的是非系统版本的 Ruby,您可以运行以下命令:

      To check that you're now using the non-system version of Ruby, you can run the following commands:

      which ruby
      

      它应该不是 /usr/bin/ruby

      ruby -v
      

      如果您使用的是 macOS Catalina,它应该不是 2.6.3.截至今天,3.0.1 是最新的 Ruby 版本.

      It should be something other than 2.6.3 if you're on macOS Catalina. As of today, 3.0.1 is the latest Ruby version.

      一旦您安装了这个新版本的 Ruby,您现在就可以安装 bundler(或任何其他 gem):

      Once you have this new version of Ruby installed, you can now install bundler (or any other gem):

      gem install bundler
      

      这篇关于您没有/Library/Ruby/Gems/2.3.0 目录的写权限.(mac 用户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆