CocoaPods Installation Failure

Hi everyone!

Recently I’ve been trying to integrate LevelPlay into my Unity project. I’ve been able to make it work on Android, but I’m having issues with iOS. LevelPlay requires CocoaPods, however when I go to the iOS Resolver / Install CocoaPods, I always get this error:

Failed to install CocoaPods for the current user.

It will not be possible to install Cocoapods in the generated Xcode project which will result in link errors when building your application.

For more information see:
  https://guides.cocoapods.org/using/getting-started.html


'gem install cocoapods --user-install --verbose' failed with code (1):
HEAD https://rubygems.org/api/v1/dependencies
404 Not Found
GET https://rubygems.org/prerelease_specs.4.8.gz
304 Not Modified
GET https://rubygems.org/specs.4.8.gz
304 Not Modified


WARNING:  You don't have /Users/arilio/.gem/ruby/2.6.0/bin in your PATH,
      gem executables will not run.
ERROR:  Error installing cocoapods:
    The last version of drb (>= 0) to support your Ruby & RubyGems was 2.0.6. Try installing it with `gem install drb -v 2.0.6` and then running the current command again
    drb requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.

I installed a newer version of Ruby via Homebrew (v3.3.2) and I’ve even successfully installed CocoaPods via the terminal in the project’s folder, yet Unity seems to recognise the preinstalled version of Ruby on MacOS (2.6.10).

I’ve tried every possible solution I came across online in forums and web articles/guides to no avail. I even found an amazing blog about the EXACT same problem I had (The fastest and easiest way to install Ruby on a Mac in 2024), followed every step and did everything successfully, yet the problem still persists.

I’m very new to terminal in MacOS and I’m still learning. I’ve just ran out of possible solutions. Any help would be appreciated. Thank you!

Ok so I managed to solve it.

- Q: Why does this happen?

  • A: Unity uses the bash shell in terminal, instead of zsh (z-shell) for some reason. zsh is the default shell in the new versions of MacOS, so when I installed Ruby, CocoaPods etc through terminal, they were installed in the zsh. So since Unity only uses the bash shell, it doesn’t recognise them.

Note that I’m new to using terminal. The explanation I gave may have some mistakes. It’s simply my understanding of the problem with CocoaPods and the macOS terminal.

In case anyone is facing the same issues here are the new steps I followed:

  1. In terminal go to Settings / General / Shells open with, and then click on Command (complete path) and replace bin/zsh with bin/bash (Use zsh as the default shell on your Mac – Apple Support (UK))
  2. Quit and Restart terminal
  3. Try to “gem install cocoapods”. It should give an error saying that you should install an older version of drb (a gem that CocoaPods depends on), so try “gem install drb -v 2.0.6
  4. Once that’s installed, if you try to install CocoaPods again it will give you another error with instructions saying that you should install activesupport v6.1.7.8, so try “gem install activesupport -v 6.1.7.8
  5. Once that’s installed finally try “gem install cocoapods” and you’re done!

Hope this is helpful

12 Likes

Hey @Arilio19, thanks for your question and solution. Your explanation makes sense. Although, I’d be hesitant to change my default shell back to bash. I ended up solving this issues by upgrading drb and activesupport in zsh but I had to sudo to update the pre-installed gems. Which I’m not a big fan of doing either. I didn’t want to go down the path of trying to get Unity to use zsh instead of bash. But I feel like that would be the “proper” way to fix this on the long run.

@Arilio19 It would be helpful if you write your macOS version and Unity version. I am facing the same error message.

Yes, this is annoying. I usually solve this issue by installing ruby via homebrew and adding the following lines to ~/.profile:

export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
export PATH="/opt/homebrew/lib/ruby/gems/3.3.0/bin:$PATH"
export PATH="$PATH:$GEM_HOME/bin"
2 Likes

Can you elaborate on this for me? I’m just starting with an attempt at ios deployment and all this mac stuff is new to me. I also installed ruby with homebrew, which is in the wrong location for Unity. What exactly is ~/.profile? Is that a Unity thing or a Mac thing?

EDIT: I appear to have solved my problem with the accepted answer. Some of the names of the files were changed but I went through a very similar process. I don’t mind switching to bash because this stupid mac is only for unity building.

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

this line solved the issue for me
reference: [Unity] iOS Resolver にて 不幸にも Failed to install CocoaPods となってしまう。実際はCocoapods が入っているのに. #Mac - Qiita

2 Likes

using unity 6 and mini m4…

compile/build your iOS project as normal and ignore the failed to install CocoaPods error. once compiled, go to the folder where your project has been built.

right click on the folder, select ‘new terminal at folder’

in terminal, type:

arch -x86_64 pod install

terminal will tell you to ignore the initially constructed Xcode project folder and use the Unity-iPhone.xcworkspace (ie. double click to open in Xcode). the it opens, select unity-phone from the left panel. fill in the details for your project and signing as normal. go to project and select archive.

this is what worked for me after dicking around and trying to jump over a zillion hurdles while continually falling on my face. hope it helps someone else.

ps. you will need to do this each time you build a unity project for iOS.

Here is how I fixed it on M1 Max with Unity 6

ruby/gem installation

brew install ruby

cocoapod installation

brew install cocoapods

~/.profile update
add the following to your ~/.profile

export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
export PATH="/opt/homebrew/lib/ruby/gems/3.3.0/bin:$PATH"
export PATH="$PATH:$GEM_HOME/bin"
export LANG=en_US.UTF-8

make sure your gem version match with the value in the export PATH

4 Likes

Thx bro, it work for me.
Although I don’t find ~/.profile there and create one myself.

This is the best answer.

None of these solutions work.
I can see pod installation in .profile, .bashrc and .zshrc but unity 6 is stupidly insisting to install cocoapods.
It tries to use built-in ruby which is outdated (2.6) and this is giving headaches.

1 Like

After reading through all of these and trying it all out, switching my terminal over to bash and installing rbenv as my ruby manager I ended up adding the following to my .bash_profile file to get away from the stupid default mac ruby instance:

eval "$(rbenv init - bash)"

I added the above line to my .bash_profile before any other statement trying the set the GEM_HOME. Safe bet is to add this right at the beginning before any PATH updates happen.

This solution worked for me, thanks.

Wanted to chime in that I was also having this issue but with Unity 6000.0.58f2

I installed rbenv through brew and then had to update $PATH in ~/.profile with the rbenv shims for it to be picked up by unity properly.

More of a step by step guide:

  1. run brew install rbenv
  2. run rbenv install [your.version.here] (I used 3.4.7)
  3. run rbenv global [your.version.here] (in my case it was rbenv global 3.4.7)
  4. run echo 'export PATH="/Users/[username]/.rbenv/shims:$PATH"' >> ~/.profile

Make sure to restart Unity AND Unity Hub and it should now work, at least it did for me.

Thank you, this worked for me

thank you so much! This should be marked as the answer!