Thank you for writing this write up! I was trying to install CocoaPods on a new Mac running macOS Catalina and did not want to use sudo as well. I also noticed zsh on Catalina, which I’m not too familiar with, but wanted to try out since it’s replacing bash. Your write up was very helpful! I did notice once small typo. Brew install cocoapods. Dependency manager for Cocoa projects. Installation support provided for macOS releases: Intel: big sur:: catalina.
After Mac OS X 10.11 sudo gem install -n /usr/local/bin cocoapods. Since the system of this machine is 10.15, choose the latter command input sudo gem install -n /usr/local/bin cocoapods. Sudo gem install -n /usr/local/bin cocoapods Successfully installed cocoapods-1.8.4 Parsing documentation for cocoapods-1.8.4 Done installing documentation. Install Xcode command line tools: To install the latest version on Xcode you need to follow the below steps: Open Xcode - Preferences - Locations tab - install latest version of Xcode command line tools. Create your first react native project in MAC: Step 7. Run your created project.
I used to install Cocoapods by following the officially recommended way sudo gem install cocoapods
. Not anymore. Sudo
can be a bad practice.
Joshua Moody in the Calabash-ios repository warns:
Using sudo is inherently dangerous. Executing a gem install with sudo is even more dangerous because gems can execute code at install time. This means they could erase parts of your hard drive or publish sensitive information to the internet. Installing gems with sudo on MacOS can overwrite the pre-installed system gems which could cause internal MacOS and Xcode tools to fail.
If it does not convince you, see what others have to say:
Jesse Squires in his post “zsh could not find CocoaPods” writes that another poor suggestion is specifying the bin dir to /usr/local/bin
when installing the gem. This is not typically where you would want gems installed.
Cocoapods sudo-less installation on a Mac with zsh
To install the Cocoapods to our user directory we need to run the command:
$ gem install cocoapods --user-install
zsh: command not found
In the terminal, if we type pod --version
the shell will probably respond with error zsh: command not found
.
We need to set the PATH
to the Cocoapods gem.
Setting the path to cocoapods in the .zprofile
The official guide recommends configuring .bash_profile
. On the newest mac_os bash shell has been replaced with zsh shell, so we need to modify .zprofile
file. The file resides in our home directory.
However, this might not work too, as the path is missing the ruby version.
First, let’s find out in the terminal the full path to the cocoapods gem:
Now back to the .zprofile
to update the path:
Testing the installation
Let us the shell know about our changes. If we have the terminal still reload the profile file with the command source ~/.zprofile
Now the command pod --version
should work. We have installed Cocoapods without sudo
and successfully added its path. That’s it.
Comment Rules: The goal is to be better at our craft. If you want to post code, insert it between the tags <code></code> Critical is fine, but if you’re rude, I'll delete your stuff. Please do not put your URL in the comment text and please use your PERSONAL name or initials and not your business name, as the latter comes off like spam. Have fun and thanks for adding to the converstaions!
moded@modeds-mbp ~ % sudo gem install cocoapods Password: Building native extensions. This could take a while... ERROR: Error installing cocoapods: ERROR: Failed to build gem native extension.current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2/ext/ffic
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20201227-2974-utuq5f.rb extconf.rb checking for ffi.h... * extconf.rb failed * Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options.
Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBYBASENAME) --with-ffic-dir --without-ffic-dir --with-ffic-include --without-ffic-include=${ffic-dir}/include --with-ffic-lib --without-ffi
Install Cocoa Pods In Mac Os Catalina Os
c-lib=${ffic-dir}/lib --enable-system-libffi --disable-system-libffi --with-libffi-config --without-libffi-config --with-pkg-config --without-pkg-config /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in trydo': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in block in trycompile' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in withwerror' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in trycompile' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in block in haveheader' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in block in checkingfor' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block (2 levels) in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in open' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in block in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in open' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in checkingfor' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in haveheader' from extconf.rb:10:in systemlibffiusable?' from extconf.rb:42:in `'To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2 for inspection. Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/gemmake.out