While executing gem ... (Gem::FilePermissionError)

Hi Guys, I am using the new Apple M1 Max and macOS Monterey, I am trying to install cocoa pod but getting errors like below. I tried to fix it with help of StackOverflow and many ways but no luck. Please help to resolve this issue.

ERROR: While executing gem ... (Gem::FilePermissionError)   You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory.

Same error over here :(

this works for me:

Step 1 (install HomeBrew)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)

  Step 2 (Run these two commands in your terminal to add Homebrew to your PATH)

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/”YOUR USER FORLDER”/.zprofile

  eval "$(/opt/homebrew/bin/brew shellenv)"

  Step 3 (now you can install cocoapods)

brew install cocoapods

Edit for gormarroquin's Step 1:- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

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:

  1. Install Ruby with a version manager such as chruby, rbenv, asdf, or RVM. I recommend chruby.
  2. 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/

To add some context to monfresh’s detailed response…

Apple officially deprecated the various scripting language runtimes that are built in to macOS back in 10.15. You can learn more about this in the Scripting Language Runtimes section of the macOS Catalina 10.15 Release Notes.

Notably, the macOS Monterey 12.3 Beta 2 Release Notes indicate that we’ve actually removed the Python 2.7 runtime from the system. While (AFAIK) there’s no concrete timeline for removing the other runtimes, if a specific scripting language runtime is important to you then it’s now time to start managing that yourself.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Open Terminal curl -L https://get.rvm.io | bash -s stable Reopen Terminal rvm install ruby-3.1.1

rvm use ruby-3.1.1

rvm --default use 3.1.1

Then this installed cocoapods as expected

sudo gem install cocoapods

kewan's answer above worked for me

I have the same problem but trying to configure a simple cronhob with Whenever Gem, here is the error:

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/bundler_version_finder.rb:80:in pwd': Operation not permitted - getcwd (Errno::EPERM) from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/bundler_version_finder.rb:80:in lockfile_contents' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/bundler_version_finder.rb:68:in lockfile_version' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/bundler_version_finder.rb:22:in bundler_version_with_reason' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/bundler_version_finder.rb:7:in bundler_version' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/bundler_version_finder.rb:45:in filter!' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:284:in matching_specs' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:272:in find_spec_for_exe' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems.rb:302:in activate_bin_path' from /usr/bin/bundle:23:in '

Do you have any idea?

  1. curl -L https://get.rvm.io%C2%A0%7C bash -s stable
  2. rvm install ruby-3.1.1
  3. sudo gem install cocoapods

with kewan's answer above worked for me also thanks

@kewan you saved my day, thanks a ton

Opening permission to with a password to unlock the computer also doesn't allow to download the gems into the gem file. Apple needs to fix this.

While executing gem ... (Gem::FilePermissionError)
 
 
Q