0

It comes to error when installing cocoapods on MacOS(M1 chip). I ran the command sudo gem install cocoapods and got the following errors.

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.
    /Library/Ruby/Site/2.6.0/rubygems/installer.rb:712:in `verify_gem_home'
    /Library/Ruby/Site/2.6.0/rubygems/installer.rb:902:in `pre_install_checks'
    /Library/Ruby/Site/2.6.0/rubygems/installer.rb:302:in `install'
    /Library/Ruby/Site/2.6.0/rubygems/resolver/specification.rb:104:in `install'
    /Library/Ruby/Site/2.6.0/rubygems/request_set.rb:194:in `block in install'
    /Library/Ruby/Site/2.6.0/rubygems/request_set.rb:182:in `each'
    /Library/Ruby/Site/2.6.0/rubygems/request_set.rb:182:in `install'
    /Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:214:in `install_gem'
    /Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:230:in `block in install_gems'
    /Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:223:in `each'
    /Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:223:in `install_gems'
    /Library/Ruby/Site/2.6.0/rubygems/commands/install_command.rb:169:in `execute'
    /Library/Ruby/Site/2.6.0/rubygems/command.rb:323:in `invoke_with_build_args'
    /Library/Ruby/Site/2.6.0/rubygems/command_manager.rb:185:in `process_args'
    /Library/Ruby/Site/2.6.0/rubygems/command_manager.rb:149:in `run'
    /Library/Ruby/Site/2.6.0/rubygems/gem_runner.rb:51:in `run'
    /usr/bin/gem:21:in `<main>'

Expectation: the pod command is correct to install and setup.

2 Answers2

6

After many searches on Apple Develop forum and I found that one solution is helpful so I sticked the code here.

Step 1: Install homebrew

$ curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
$ /bin/bash install.sh

Step 2: brew install chruby ruby-install

Step 3: brew install cocoapods

Step 4: brew upgrade cocoapods

Now you can use pod install on your iOS project.

  • I have solved my problem with above answer and with :: *1. brew command not found answer link: https://www.makeuseof.com/zsh-command-not-found-brew-fix/ *2. Flutter Doctor CocoaPods not installed answer link: https://stackoverflow.com/a/64431181/3968301 – Shrikant Tanwade Aug 17 '23 at 14:23
0

From what I found online is that this issue is caused due to Mac OS default installation of Ruby and it is old version. You would have to update it using home-brew

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

step 2: Install Ruby Manager brew install ruby-install chruby

step 3: add this to your zsh profile source /usr/local/opt/chruby/share/chruby/chruby.sh and source /usr/local/opt/chruby/share/chruby/auto.sh

step 4: save it

step 5: write ruby-install --latest ruby to install latest ruby version

step 6: restart terminal and check if new version has been installed ruby --version

step 7: finally sudo gem install cocoapods

if you are unable to follow these instruction then please follow this video: https://www.youtube.com/watch?v=uZD2EQbBqPg

Atharv Sharma
  • 125
  • 2
  • 8