Hi @iappvk, the reason why you are getting that error is because Apple doesn't allow you to install gems directly into the version of Ruby that came preinstalled on your Mac.
The correct way to install gems on a Mac is to install a separate version of Ruby. There are two ways to do that:
- Install Ruby with a version manager such as chruby, rbenv, asdf, or RVM. I recommend chruby.
- Install Ruby with Homebrew
I recommend option 1 because it allows you to install multiple versions of Ruby at the same time, and have them be independent of each other, and easily switch between them.
In either case, you will need to install Homebrew first.
Then, you'll be able to install chruby
and ruby-install
with Homebrew.
And once they are configured, you'll be able to install the latest version of Ruby with ruby-install
.
Finally, you'll be able to install cocoapods with gem install cocoapods
.
The easiest way to install everything automatically is to use https://www.rubyonmac.dev, a script that sets up a proper Ruby development environment for you with a single command.
Here's a more detailed article if you want to do everything manually: https://www.rubyonmac.dev/you-dont-have-write-permissions-for-the-library-ruby-gems-2-6-0-directory/