'Could not find 'minitest' (>= 5.1) among 39 total gem(s)

Situation:

I am trying to setup Cocoapods.

I'm on OSX 12.2. I have installed Ruby with Homebrew. When I run gem list minitest (5.15.0) is listed.

Running pod setup in terminal fails because it could not find minitest (>=5.1) among 39 gems.

I noticed that the directory searched looks to be the OSX system ruby installation at Library/Ruby/Site/2.6.0; rather than ruby 3.1.0 (at /usr/local/opt/ruby/bin/ruby) that I installed with Homebrew.

I assume that what I need to do is point terminal to ruby 3.1.0; but, I double checked my .zhsrc file, and it looks to be in order (I learnt about this from reading SO questions and Ruby and Cocoapods setup guides - so I may be very wrong about this).

This is the contents of .zhsrc:

export PATH="/usr/local/sbin:$PATH"

# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/sean/Desktop/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/sean/Desktop/google-cloud-sdk/path.zsh.inc'; fi

# The next line enables shell command completion for gcloud.
if [ -f '/Users/sean/Desktop/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/sean/Desktop/google-cloud-sdk/completion.zsh.inc'; fi
export PATH="/usr/local/opt/ruby/bin:$PATH"

. /usr/local/opt/asdf/libexec/asdf.sh

Can you please help me figure out what I need to do to get pod setup to succeed?

Things I have tried:

  1. I tried uninstalling and reinstalling cocoapods sudo gem install cocoapods

  2. I tried uninstalling and reinstalling cocoapods with homebrew brew install cocoapods.

  3. Install bundler from this SO suggestion - I tried this and got the error Could not locate Gemfile

  4. I also ran sudo gem install minitest -v 5.15.0 - and am still getting the same error. From this SO question.

Extra Information Below:

If it helps, this is my path:

/usr/local/opt/ruby/bin:/Users/sean/Desktop/google-cloud-sdk/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Applications/Wireshark.app/Contents/MacOS

Here are images of the error:

enter image description here

enter image description here

I have looked at these Stackoverflow questions (and many many more) and tried the suggested solutions to no avail:

Could not find 'minitest' (~> 5.1) among 42 total gem(s) (Gem::MissingSpecError)

Could not find 'cocoapods' (>= 0) among N total gem(s) (Gem::LoadError)

How do I install CocoaPods?

Rails: Could not find minitest-4.7.5 in any of the sources



Solution 1:[1]

Solved the situation by following this.

Specifically - I added the following text to the end of the .zshrc file:

if [ -d "/usr/local/opt/ruby/bin" ]; then
  export PATH=/usr/local/opt/ruby/bin:$PATH
  export PATH=`gem environment gemdir`/bin:$PATH
fi

And then critically - quitting terminal and re-opening it.

Solution 2:[2]

Specifically - I added the following text to the end of the .zshrc file:

if [ -d "/usr/local/opt/ruby/bin" ]; then export PATH=/usr/local/opt/ruby/bin:$PATH export PATH=gem environment gemdir/bin:$PATH fi

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sean
Solution 2 Hamid Kia