问题
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!
回答1:
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:
- Install a separate version of Ruby that does not interfere with the one that came with your Mac.
- Update your
PATH
such that the location of the new Ruby version is first in thePATH
. The list of directories, and the order in which the computer looks them up to find executable programs is called thePATH
. If you typeecho $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 yourPATH
by runningecho 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
, followed bysource ~/.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
回答2:
If you don't want to run sudo
then install ruby using homebrew
brew install ruby
export GEM_HOME="$HOME/.gem"
gem install rails
You may want to add export GEM_HOME="$HOME/.gem"
to your ~/.bash_profile
or .zshrc
if you're using zsh
回答3:
It's generally recommended to use a version manager like rbenv or rvm. Otherwise, installed Gems will be available as root
for other users.
If you know what you're doing, you can use sudo gem install
.
回答4:
I have faced same issue after install macOS Catalina. I had try below command and its working.
sudo gem update
回答5:
Worked for me using the parameter --user-install
running following command:
gem install name_of_gem --user-install
Then he started to fetch and install it.
Edit
There was one gem I still could not install (it required the Ruby.h headers od the Ruby development kit or something), then I tried with the different Version managers, but somehow that did not really work as it was stated in the documentations how to just install and switch (it did just not switch the versions).
Then I removed all the installed version managers and afterwards with brew install ruby
the latest version and did set the PATH variable, too. (It will be mentioned after the installation of ruby from brew)
回答6:
Run this
$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.zshrc:
eval "$(rbenv init -)"
Follow instructions, (in my case add to ~/.zshrc) ;)
Also important: Changes only take effect if you reboot your console. Two options
- Enter
source <modified file>
- close and open again
回答7:
Issues I had :- You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.
Solution worked for me: sudo gem install rails -v 6.0.0
回答8:
If you have installed ruby separately and installed ruby using rbenv/rvm you budler might point to different versions.
try
gem env home
and
ruby -v
both should point to same version.check you have installed ruby using rbenv/rvm, If so delete the ruby version you installed separately.
In order for gem to work, you must invoke rbenv,
rbenv shell <ruby version>
and
rbenv global <ruby version>
I am not sure how RVM works. Let me know if this works.
回答9:
Solution for Mac
Install/update RVM with last ruby version
\curl -sSL https://get.rvm.io | bash -s stable
Install bundler
gem install bundler
after this two commands (sudo) gem install ....
started to work
来源:https://stackoverflow.com/questions/51126403/you-dont-have-write-permissions-for-the-library-ruby-gems-2-3-0-directory-ma