164

After upgrading to macOS High Sierra CocoaPods is not working. While it is tempting to move away from CocoaPods, it's unfortunately not in scope right now. The error message is below.

zsh: /Users/****/.gems/bin/pod: bad interpreter: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin: no such file or directory

I realize that the error stems from Ruby being upgraded but what is the easies fix? Trying to make CocoaPods use the new ruby version yields other errors.

Edit: For now i installed Ruby 2.0 with rvm install 2.0.0 and rvm use 2.0.0 and then reinstalled CocoaPods sudo gem install cocoapods. Seems to be working now.

Maciej Swic
  • 11,139
  • 8
  • 52
  • 68
  • Did you update the Command Line Tools? – matt Jun 06 '17 at 17:30
  • @matt Yes, `sudo xcode-select -s /Applications/Xcode-beta.app` and `sudo xcode-select --install` and followed the GUI from there. – Maciej Swic Jun 06 '17 at 18:22
  • I was thinking of the ones here: https://developer.apple.com/download/more/ I often find external tools don't work until I install those. – matt Jun 06 '17 at 19:04

25 Answers25

418

According to https://github.com/CocoaPods/CocoaPods/issues/6778 reinstalling CocoaPods should solve this issue:

sudo gem install cocoapods
David Brabant
  • 41,623
  • 16
  • 83
  • 111
zeisi
  • 5,520
  • 2
  • 22
  • 21
119

After upgrading to macOS High Sierra, get it fixed with following commands:

sudo gem update --system
sudo gem install -n /usr/local/bin cocoapods

once it will be finished then write below command:

pod install

This solution has worked for me...!!!

mital solanki
  • 2,394
  • 1
  • 15
  • 24
  • 1
    I got "ERROR: While executing gem ... (Errno::EPERM) Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem" when running the first command, but running the second still made "pod install" work. Thanks. – Bryce Sandlund Nov 19 '17 at 23:54
  • Despite the "warning", I'm going to say thanks here anyway. This was the only thing that worked for me. Simply reinstalling cocoapods (several times) made no difference until I did both of these steps. So - thanks! – huygir Nov 20 '17 at 14:22
  • I had to run the ruby update through the following command: `sudo gem update -n /usr/local/bin --system` – Paul Popiel Dec 03 '17 at 03:30
  • Worked for me (cocoapods 1.5.3). – atereshkov Jul 07 '18 at 10:21
  • After literally trying hundreds of other proposed solutions and spending hours and hours this one finally worked. I can now safely say I love you just as much as I hate the Apple/Mac dev environment! Thanks. – Arthur May 21 '21 at 09:40
30

I got this error while installing the CocoaPods

ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.

And I used this statement. It worked!

sudo gem install cocoapods -n /usr/local/bin
Danh Huynh
  • 2,337
  • 1
  • 15
  • 18
12

This worked for me, although I had to do

sudo gem install cocoapods
Pang
  • 9,564
  • 146
  • 81
  • 122
Andrew Smith
  • 2,919
  • 2
  • 22
  • 25
11

This solved my problem:

$ brew install ruby
$ gem install -n /usr/local/bin cocoapods
Đorđe Nilović
  • 3,600
  • 1
  • 25
  • 20
  • Please give a short explanation of what the posted code does so people that are new to this technology have a change to understand and re-use your answer :-) – Mathieu VIALES Oct 23 '17 at 13:05
  • 1
    People new to cocoapods should know how to read like the others. – thibaut noah Oct 23 '17 at 13:07
  • @MathieuVIALES, the "brew install ruby" assumes you already have Homebrew packager (https://brew.sh). That command then installs (or probably technically re-installs ruby since you actually need ruby to install Homebrew itself). The next line "gem install -n /usr/local/bin cocoapods" reinstalls the CocoaPod program (more at https://cocoapods.org). – Eddie Eddie Eddie Mar 01 '19 at 19:21
9

Simply run below command:

sudo gem install -n /usr/local/bin cocoapods
Harshal Wani
  • 2,249
  • 2
  • 26
  • 41
8

This works for me:

brew link --overwrite cocoapods
Yun CHEN
  • 6,450
  • 3
  • 30
  • 33
6

So I ran into this problem as well after having updated to High Sierra, and it seems like there's been some changes to a location of file that the ruby framework was accessing.

You can solve it using the,

sudo gem install cocoapods

and then update pods as well with for safe measures

pod repo update 

and finally

pod install

to make the pod file work again.

Hope this helps out :)

T. Hyldgaard
  • 328
  • 8
  • 16
6

Try using

sudo gem update --system

Before

sudo gem install cocoapods

This worked for me

David
  • 61
  • 1
  • 2
6

Cocoapods install process:

  1. sudo gem install cocoapods (if you have any problem cocoapds, please update gem file)

  2. sudo gem update --system

  3. sudo gem install cocoapods

Jan Černý
  • 1,268
  • 2
  • 17
  • 31
Sheshu Solo
  • 61
  • 1
  • 2
5

For me, I had to:

gem uninstall cocoapods
which pod

It still showed it in the path, so I deleted that. Made sure it still didn't show up.

Then

gem install cocoapods
djunod
  • 4,876
  • 2
  • 34
  • 28
4

Go to Terminal...

step 1). sudo gem install cocoapods

after completion of install cocoa pods then

step 2). pod repo update

Completed

4

MacOS High Sierra uses ruby 2.3 by default. After upgrading to it, some old ruby gems might not function properly. This problem occurs to me when I ran the bundle command (bundler is a ruby gem; it has a utility called bundle).

So, to clarify, any old ruby gems (cocoapods, bundler, etc) that are trying to access ruby 2.0 will fail.

The solution is to reinstall those old gems in a directory where you have permissions to write.

For cocoapods,

sudo gem install cocoapods -n /usr/local/bin

will do the trick.

You can optionally upgrade your gem system if you like before the install:

sudo gem update --system

This may prompt to you that the upgrading has failed. But actually, if you type:

gem --version

You can see that the upgrading has been successful.

For bundler or other gems, try to do the same:

sudo gem install gem-to-install(for example, bundler) -n /usr/local/bin

About the -n option. Don't miss that. You can check the gem documentation if you want.

So, the solution is all about reinstalling the old gem to a proper directory.

Jiang Wang
  • 273
  • 3
  • 9
3

I also encountered this error after installing High Sierra.

ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.

I used the following statement identified by Danh Huynh (see above) and It worked!

sudo gem install cocoapods -n /usr/local/bin
kgangadhar
  • 4,886
  • 5
  • 36
  • 54
2

Sudo-less .zhs-friendly solution

Modern macOS discourages using sudo and shifts from bash to zsh, so this answer may be useful if you are not going to fight with the fashion.

  1. Insure that .zshenv exists by touch ~/.zshenv command. Configure the RubyGems environment by adding following lines:

    export GEM_HOME=$HOME/.gem
    export PATH=$GEM_HOME/bin:$PATH
    

    Don't forget to relaunch Terminal.

  2. Run gem install cocoapods.
kelin
  • 11,323
  • 6
  • 67
  • 104
  • ERROR: While executing gem ... (Errno::EACCES) Permission denied @ dir_s_mkdir - /Users/shubhamojha/.local/share/gem/specs – Shubham Ojha May 26 '22 at 15:14
1

While I'm doing the same I got another error saying that

ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

Then I did this and worked fine.

sudo gem uninstall cocoapods

sudo gem install cocoapods
Himanth
  • 2,381
  • 3
  • 28
  • 41
1

Had a same issue, resolution:

  1. Reinstall ruby

    brew install ruby

  2. Reinstall Cocoa Pods

    sudo gem install cocoapods

Anton Eregin
  • 8,140
  • 1
  • 12
  • 14
1

This is a common problem when upgraded to Mac OSX High Sierra.

Fix is simply installing Cocoapods (again):

sudo gem install cocoapods
Shobhit C
  • 828
  • 10
  • 15
1

Running this on terminal worked for me:

sudo gem install cocoapods
AMT
  • 136
  • 5
0

After using the below command on the terminal, I am able to install cocoa pods in my project.

sudo gem install cocoapods --source http://rubygems.org
Sonam Maniar
  • 312
  • 4
  • 8
0

I faced this issue also but fixed it in less dramatical way as various re-installation / updating. Just updated PATH environment variable to point out my existing (2.6.0) ruby version.

0

I had the same issue after upgrading to Catalina.

  1. I updated ruby install by first installing brew and ruby using these directions. https://gorails.com/setup/osx/10.15-catalina (but only ruby, not rails, etc.)

  2. Then I reinstalled cocoapods using the instructions above.

    sudo gem install cocoapods

Then after all that I still received the error above. Then I typed 'zsh' to spawn a new shell and pull in configuration settings in the ~/.zshrc file. After this 'pod update' command worked again.

Larry Ricker
  • 199
  • 1
  • 7
0
    curl -sSL https://get.rvm.io | bash -s stable
    sudo update gems
    rvm install 2.6.0
    sudo gem install cocoapods
  • Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes – Boken Dec 03 '20 at 14:01
0

I used homebrew to install cocoapods on High Sierra (macOS 10.13.6) it works for me

brew install cocoapods

after this flutter doctor shows no errors.

I am able to deploy my Flutter app to IOS XS Max

  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/30514920) – micke Dec 06 '21 at 10:15
-1
If cannot install new version cocoapods, example below:
1. Please remove Command line tools
sudo rm -rf /Library/Developer/CommandLineTools
2. Install new Command line tools version
sudo xcode-select --install
3. after installing run below command
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
siddhant
  • 39
  • 2