Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve error "command not found: pod" despite cocoapods successful install?

I have run sudo gem install cocoapods. Lots of gems installed and no error shown. But despite that, when I run pod setup, I keep getting error "command not found: pod". I tried rerun the cocoapods installation. And the pod command still can't be run. How to fix this? I use MacOS.

like image 218
Chen Li Yong Avatar asked Nov 04 '25 13:11

Chen Li Yong


2 Answers

Ultimately, I decided to uninstall every gems and every ruby version in my Mac, and start over. I see tutorial from here, and basically the important things when installing Cocoapods are:

1> Make sure Homebrew is installed. Or run this command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2> Install Ruby using Homebrew, without sudo.

brew install ruby

3> Important: add path below to your PATH environment variable on your zshrc profile.

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc

4> Reload the zshrc profile so the newly added path can take effect.

source ~/.zshrc

5> Make sure the newly installed Ruby is in effect.

which ruby

this should return /usr/local/opt/ruby/bin/ruby

6> Install cocoapods using Ruby, again, WITHOUT sudo.

gem install cocoapods

7> Test that the cocoapods correctly installed and the Gemfile correctly built by run simple command:

pod

If this returns something other than "command not found" error, you installed it correctly.

Troubleshoot:

1> Error "access not found" or similar when installing cocoapods.

Answer: you most likely still using the "system Ruby", which has different place of gems installation, and your user account likely won't have access to the path.

Try to run which ruby.

If it says: /usr/local/opt/ruby/bin/ruby, then this is already newly installed ruby, and there's nothing wrong with this process.

If it says: usr/bin/ruby, then this is system Ruby. You need to run step 3 and step 4 to make sure the new path is activated.

2> Running pod gives error: "command not found".

This is most probably caused by the same path issue thing as problem #1. Just retry step 3 and 4.

3> Running pod gives error: "Gemfile not found".

This is most probably caused by you installing cocoapods using sudo, which will complicates the hell of your installation. This causes the Gemfile to failed to be built during gem installation. This is also my problem, which I resolved by uninstalling every gems and every ruby installation, and retry from beginning.

like image 107
Chen Li Yong Avatar answered Nov 06 '25 03:11

Chen Li Yong


I had the same problem after installing cocoapods with brew. The actual problem was that it was not linked. My problem was solved by use the recommended command brew link cocoapods. If an error is raised by the above command use brew link --overwrite cocoapods to force linking

like image 31
John Mwangi Avatar answered Nov 06 '25 04:11

John Mwangi