. Advertisement .
..3..
. Advertisement .
..4..
I am working on programs, but I found the following warning message:
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
Is there any way to stabilize the issue “you don’t have write permissions for the /library/ruby/gems/2.3.0 directory.”?
I read a lot of topics about this, but all of them were trying to install anything. Is this the correct way, or any recommendation for me?
Please find the beginning command below:
source "https://rubygems.org"
gem "rspec", "~> 3.2.0"
The cause:
This error often happens due to Ruby is installed on all Macs by Apple, and the /Library /Ruby/ Gems/2.3.0 directory is the default location where gems will be installed. However, this directory is not used for modifying, so you are not permitted to write to Apple.
Solution:
You can resolve this solution by installing ruby with homebrew as below:
If you are using zsh, perhaps you would like to add
export GEM_HOME="$HOME/.gem"
to your~/.bash_ profile
or.zshrc
Remember that old versions of gems are kept by RubyGems, so you can free clean after updating:
Update:
With one command , I have a-paid script that will create a Ruby environment.
Also, I updated my guide. It explains how to install Ruby gems on a Mac. I recommend only using
chruby
orruby-install
.MacOS will not allow you to modify the Ruby version that came with your Mac. It is possible to install gems such as
bundler
with a different version of Ruby than the one supplied by Apple.sudo
is not recommended for installing gems or changing permissions on system files and directories. This applies even if you are a skilled programmer. We need to stop giving this poor advice. This article explains why sudo should not be used to install gems.Two main steps are required to find the solution:
PATH
is updated so that the new Ruby version’s location is the first in thePATH
. This is done automatically by some tools. You should be familiar withPATH
to understand how it works. This will help you understand why you get ” command failed to find” errors, as well as how you can fix them.There are many ways to install Ruby on Mac. The best method that I recommend and which I wish was more common in the various installation guides out there is to use an automated script such as Ruby for Mac, which will create a proper Ruby environment.
It saves everyone a lot of time. Our most precious and limited resource is time. It is a waste of time to make things manual when you can automate them with perfect results every time.
It also drastically reduces human error and errors due to incomplete instructions.
Continue reading if you prefer to do it manually. You will first need to install . This installs the required command line tools and makes it easy for you to install any other tools.
These are the easiest ways to install Ruby in a different version.
You can switch between multiple Ruby versions easily [RECOMMENDED]
Select one of the following options:
Benv can be installed using Homebrew
RVM
asdf
You can install Ruby as follows if you choose
chruby
orruby-install
.After you have installed everything and set up your
.zshrc
/.bash_profile
according the instructions, close Terminal and restart it. Then, switch to the Ruby version you prefer. It would look something like this forchruby
:Which shell are you using will determine whether you need to set up
.zshrc
or.bash_profile
.You can be certain that you don’t require more than one Ruby version at once (other than the one that comes with macOS).
Even if you don’t think you’ll need it now, eventually you will and you won’t be able switch easily. This can cause confusion and headaches.
Next, run this command to update your
PATH
The
2.7.0
command assumes Homebrew has installed a Ruby version starting with2.7
. You can useruby -v
to check if you are using a different version.Next, “refresh” the shell to allow these changes take effect.
You can also open a new tab in Terminal, quit Terminal and start it again.
If you’re using Bash, replace
.zshrc
by.bash_profile
You can read my guide to determine which shell is being used.You can use the following commands to verify that you are using the non-system Ruby version:
It should not be
/usr/bin/ruby
If you are using macOS Catalina or Monterey, it should be at least 2.6.3. 3.1.0 is the most recent Ruby version as of early 2022.
After you have installed this version of Ruby, you can install bundler (or any other gem).