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

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

问题描述

下面是我需要做的.

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

所以,我输入 gem安装捆绑器 到终端,并得到 您对/Library/Ruby/Gems/2.3.0目录没有写权限.

,它在原子的项目文件中 *来源" https://rubygems.org " gem"rspec",〜> 3.2.0" *

我的问题是:

终端似乎给了我响应,因为我不应该在ruby上进行任何更改,而我需要 bundle install 在atom里面?谁能告诉我如何使用原子或在原子中运行任何东西?

非常感谢您!

解决方案

您是正确的,macOS不允许您使用Mac随附的Ruby版本更改任何内容.但是,可以使用不干扰Apple提供的Ruby的另一版本来安装bundler这样的gem.

强烈建议不要使用sudo安装gem,或更改系统文件和目录的权限,即使您知道自己在做什么.我们可以停止提供这个不好的建议吗?

该解决方案涉及两个主要步骤:

  1. 安装另一种不干扰Mac随附版本的Ruby.
  2. 更新您的PATH,以使新Ruby版本的位置位于PATH中的第一位.目录列表以及计算机查找可执行程序的顺序称为PATH.如果在终端中键入echo $PATH,将看到目录列表,以冒号分隔.

有几种方法可以在Mac上安装Ruby.我建议并希望在各种安装说明中更普遍的最佳方法是使用自动脚本,它将为您设置合适的Ruby环境.这样可以大大减少由于指令不足而导致出错的可能性,这些指令会使用户手动执行大量操作,然后由用户自行决定所有必要步骤.

您可以采取的另一种方法是花费额外的时间手动做所有事情,并希望做到最好.首先,您将要安装 Homebrew ,这使得安装其他工具和macOS应用程序变得容易.

然后,安装单独的Ruby版本的4种最流行的方法是:

如果您同时不需要多个版本的Ruby(macOS随附的版本除外)

  • 自制软件-安装完成后,用brew install ruby安装ruby,然后通过运行echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile然后是source ~/.bash_profile
  • 更新PATH

如果您想轻松地在许多Ruby版本之间切换的灵活性

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

which ruby

应该不是/usr/bin/ruby

之外的其他内容

ruby -v

应该不是2.3.7.到目前为止,2.6.1是最新的Ruby版本.

一旦您安装了这个新版本的Ruby,现在就可以安装捆绑程序:

gem install bundler

below is what I need to do.

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.

So, I typed gem install bundler to terminal, and got You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

and this was in the project file in atom *source "https://rubygems.org" gem "rspec", "~> 3.2.0" *

My question is:

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?

Thank you so much!

解决方案

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.

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?

The solution involves two main steps:

  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. The list of directories, and the order in which the computer looks them up to find executable programs is called the PATH. If you type echo $PATH in Terminal, you will see the list of directories, separated by a colon.

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 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.

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 makes it easy to install other tools and macOS apps.

Then, the 4 most popular ways to install a separate version of Ruby are:

If you don't need more than one version of Ruby at the same time (besides the one that came with macOS)

  • Homebrew - once it's installed, install ruby with brew install ruby, then update your PATH by running echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile, followed by source ~/.bash_profile

If you would like the flexibility of easily switching between many Ruby versions

  • chruby and ruby-install - my personal recommendations and the ones that are automatically installed by the aforementioned script. These can be installed with Homebrew.

  • rbenv - can be installed with Homebrew

  • RVM

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

which ruby

It should be something other than /usr/bin/ruby

ruby -v

It should be something other than 2.3.7. As of today, 2.6.1 is the latest Ruby version.

Once you have this new version of Ruby installed, you can now install bundler:

gem install bundler

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

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