266

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.

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
user3670235
  • 3,125
  • 3
  • 13
  • 17
  • Ruby installation incorrect? – SwiftArchitect Jul 18 '15 at 00:50
  • 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 Aug 27 '15 at 08:08
  • 1
    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 Aug 27 '15 at 15:53

20 Answers20

514

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.

Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
Torre Lasley
  • 7,243
  • 3
  • 24
  • 12
127

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
Rendel
  • 1,794
  • 3
  • 13
  • 16
  • 12
    This was the solution for me after upgrading to Catalina. – Joe Nov 17 '19 at 19:01
  • 1
    You might have to install separate package for the ruby development environment, ruby-dev or ruby-devel for example. – Chandni Apr 02 '20 at 15:10
  • 1
    Along with this I also had an issue with openssl that I had to fix first - `brew uninstall openssl & brew install openssl` – Jacksonkr May 11 '20 at 13:59
77

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

sudo gem install -n /usr/local/bin cocoapods
Shan Ye
  • 2,622
  • 19
  • 21
54

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.

hooknc
  • 4,854
  • 5
  • 31
  • 60
Niraj Paul
  • 1,498
  • 14
  • 22
23
brew link --overwrite cocoapods

This line saved my day.

goodhyun
  • 4,814
  • 3
  • 33
  • 25
17

i fixed it by running brew install ruby

user3670235
  • 3,125
  • 3
  • 13
  • 17
14

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

CocodyRockStar
  • 230
  • 2
  • 8
6

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
Himanth
  • 2,381
  • 3
  • 28
  • 41
  • Most likely you didn't need to uninstall. That error just says you don't have the correct permissions to do what you were trying to do. So adding `sudo` was all you needed. See the comment from [https://stackoverflow.com/users/877341/blackhawk4152] above – PJayRushton Oct 04 '17 at 14:17
6

On my mac this solved the problem:

brew uninstall cocoapods

brew install cocoapods
aaa
  • 601
  • 6
  • 13
6

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'.

MangoLassi
  • 577
  • 6
  • 7
5

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 a step-by-step guide, check out my detailed tutorial for setting up Ruby on a Mac.

monfresh
  • 7,974
  • 1
  • 25
  • 22
4

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
Gayal Kuruppu
  • 1,261
  • 1
  • 17
  • 29
4

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
Dharman
  • 30,962
  • 25
  • 85
  • 135
Gurunath Sripad
  • 1,308
  • 2
  • 14
  • 24
2

Fixed with

brew upgrade cocoapods
cartland
  • 599
  • 4
  • 8
0

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

giorgos.nl
  • 2,704
  • 27
  • 36
0

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.

Pinwheeler
  • 1,061
  • 2
  • 13
  • 26
0

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.

Raseone
  • 9
  • 1
0

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 .

0

re-installing ruby solving issues on my case (error happen after I upgrade Mac OS to Monterey). it's take a bit of time to reinstall but it worked

Debian G
  • 1
  • 2
0

Technically Symlink to Ruby is broken.

Fix it by executing command: ln -s /opt/homebrew/Cellar/ruby/<version> /opt/homebrew/opt/ruby

  • This is a duplicate answer. Many users have described methods similar to solve the problem. – Ben A. Aug 30 '23 at 17:11
  • Mostly others are suggesting to reinstall ruby or cocoapods. Both are installed correctly. Its only symlink issue. I do not find any such answer. – Azim Ansari Aug 30 '23 at 17:54