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.

Post not yet marked as solved Up vote post of iappvk Down vote post of iappvk
  • Same error over here :(

  • 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


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

  • After using the HomeBrew to install cocoapods, I check the status of flutter it still says ---

        You appear to have CocoaPods installed but it is not working.     This can happen if the version of Ruby that CocoaPods was installed with is     different from the one being used to invoke it.     This can usually be fixed by re-installing CocoaPods.```
  • In the above case, use this command to reinstall CocoaPods:- gem install cocoapods --user-install

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/

  • This is the correct answer, and clean solution. Thank you.

  • Awesome. Thank you

Add a Comment

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"

  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

Add a Comment

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.