Running pod setup gives me "bad interpreter: No such file or directory" error
RubyMacosCocoapodsPodspecRuby Problem Overview
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.
Ruby Solutions
Solution 1 - Ruby
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.
Solution 2 - Ruby
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
Solution 3 - Ruby
After upgraded to High Sierra, I got the same error, just reinstalled the cocoapods
sudo gem install -n /usr/local/bin cocoapods
Solution 4 - Ruby
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.
Solution 5 - Ruby
brew link --overwrite cocoapods
Solution 6 - Ruby
i fixed it by running brew install ruby
Solution 7 - Ruby
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
Solution 8 - Ruby
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
Solution 9 - Ruby
On my mac this solved the problem:
brew uninstall cocoapods
brew install cocoapods
Solution 10 - Ruby
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'.
Solution 11 - Ruby
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
Solution 12 - Ruby
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:
- Install Homebrew (which also installs the prerequisite Apple command line tools)
- Install a Ruby manager (such as chruby, rbenv, asdf, RVM) - most of these can be installed with Homebrew
- 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 - Restart the terminal (or open a new tab) for the shell changes to take effect - another step that is often overlooked
- Install a specific version of Ruby using the Ruby manager
- 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.
Solution 13 - Ruby
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
Solution 14 - Ruby
Fixed with
brew upgrade cocoapods
Solution 15 - Ruby
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
Solution 16 - Ruby
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.
Solution 17 - Ruby
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.
Solution 18 - Ruby
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 .