249
votes

Recently I tried to do pod setup and I get this error:

-bash: /usr/local/bin/pod: /usr/local/opt/ruby/bin/ruby: bad interpreter: No such file or directory

I followed Ray Wenderlich's guide to install CocoaPods and I get this issue so I have no idea what is going on.

18
Ruby installation incorrect?SwiftArchitect
What is your system? [Darwin (Mac OS X)?] How did you install Ruby? [brew? ports? from source?] How are you managing Ruby versions? [RVM? rbenv?] Which guide by Ray Wenderlich did you follow? [there are several]mwp
The error basically tells you that the interpreter you are attempting to use is not there. Look at the /usr/local/bin/pod, first line (one that starts with #!) and you should see the ruby interpreter there. Is there anything in /usr/local/opt/ruby? Are you using rbenv, rvm?Mircea

18 Answers

505
votes

I encountered this problem when upgrading to Mac OS High Sierra.

This was my fix:

sudo gem install cocoapods

I found this answer on the CocoaPods issue list on Github.

119
votes

This happened when I upgraded to Catalina. I solved it by running:

sudo gem install -n /usr/local/bin ruby
sudo gem install -n /usr/local/bin cocoapods
76
votes

After upgraded to High Sierra, I got the same error, just reinstalled the cocoapods

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

Same issue I was facing when I updated our system from Sierra to Mojave. Also works for Catalina

The following steps worked:

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

I got the help from the following link.

19
votes
brew link --overwrite cocoapods

This line saved my day.

15
votes

i fixed it by running brew install ruby

13
votes

The following worked for me:

Select Command Line Tools in XCode.

    XCode > Preferences > Locations > Command Line Tools > XCode 11.X.X

In terminal execute:

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

https://stackoverflow.com/a/60464653

6
votes

While I'm trying to install again then 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
6
votes

On my mac this solved the problem:

brew uninstall cocoapods

brew install cocoapods
6
votes

After upgrading from OS X Mojave to OS X Catalina I received this message when running pod init or pod --version: -bash: /Users/mangolassi/.gem/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory

I don't like the idea of sudo gem install cocoapods so I have my .cocoapods folder in my user directory and I've modified my .bash_profile to point to it. The error I received was because the version 2.3 was hard coded in this file: /Users/eric/.gem/bin/pod and Catalina came with 2.6.

It's possible that using sudo install would overwrite this file successfully, and probably does, but I wanted to keep my original setup.

I was able to to just modify the first shebang line of the file /Users/eric/.gem/bin/pod to have a path with 2.6 instead of 2.3 and it worked. The entire change was changing the '3' to a '6' in my chase as the version was still '2'.

3
votes

for MACOS X Catalina

Tried most of the answers but none worked. If the above doesn't work try Opening Xcode preferences > Locations > selecting Command Line Tools to Xcode. Then install cocoapods

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

I came across a similar issue when I tried upgrading the cocoa pods version using:

brew upgrade cocoapods

To fix this, cocopaods had to be linked with xcodeproj using the command below:

brew link cocoapods

If the linking fails, then you should be able to link by overwriting the previously existing link as follows:

brew link --overwrite cocoapods
2
votes

Fixed with

brew upgrade cocoapods
2
votes

The error in the original post is due to an improperly configured Ruby environment. You should never use sudo to install gems, no matter how many times you see it as an accepted answer on Stack Overflow.

At a high level, setting up a proper Ruby development environment on a Mac involves six steps:

  1. Install Homebrew (which also installs the prerequisite Apple command line tools)
  2. Install a Ruby manager (such as chruby, rbenv, asdf, RVM) - most of these can be installed with Homebrew
  3. Configure the Ruby manager by adding the appropriate lines to your shell file (~/.bash_profile or ~/.zshrc) - each manager will have instructions for doing this, and this is a typical step that people miss
  4. Restart the terminal (or open a new tab) for the shell changes to take effect - another step that is often overlooked
  5. Install a specific version of Ruby using the Ruby manager
  6. Switch to that version of Ruby using the Ruby manager

My personal preference is chruby with ruby-install. For more details and a script that can automate this whole process, check out my answer here: https://stackoverflow.com/a/54873916/928191

As the accepted answer mentions, you can also install Ruby with Homebrew, but you also need to make sure to set your PATH in your shell file. Instructions for this are in my answer linked above.

0
votes

In my case nothing of the above worked. I had ruby 2.3.0 installed and I had to downgrade to 2.0.0:

gem update --system 2.0.0

0
votes

The "rubyist approved" way of doing this is to install a ruby version manager (rbenv) and install cocoapods through that. Messing with sudo and your rubygems is going to lead to tears.

0
votes

Find the pod file. Mine was located at usr/local/bin/pod

You'll find that the top line says version 2.3. Edit this file to the correct version number. Save a copy of the original incase you mess it up.

Try your pod related commands again.

Worked for me after days of trying everything.

0
votes

vi pod then replace the ruby path 2.3 one to the path which u get by using which ruby command in terminal then do pod setup it will work this worked for me after trying all the listed solutions .