20

The React Native docs recommend installing Cocoapods with sudo gem install cocoapods, but I'm used to using Homebrew and have seen elsewhere that people install it with brew install cocoapods. When I try installing it with Homebrew, I get this warning:

Warning: Treating cocoapods as a formula. For the cask, use homebrew/cask/cocoapods

What I Want To Know:

  1. What's the difference, if any, between installing Cocoapods with sudo gem install cocoapods and with brew install cocoapods

  2. If I install it with Homebrew, should I install the regular package or the cask? What's the difference?

gkeenley
  • 6,088
  • 8
  • 54
  • 129

2 Answers2

6

macOS comes with a pre-installed version of Ruby. If you try to install a gem through pre-installed Ruby, you've to use sudo by default witch is not a good practice.

Another option is to install CocoaPods in your user-level directory by following instructions available on the Sudo-less installation section.

I would suggest you install CocoaPods using brew. It's a little cleaner option and you can update it easier.

The cocoapods cask is for CocoaPads App and the formula is for the CLI only version.

nekofar
  • 1,497
  • 1
  • 18
  • 25
  • To add some details to this excellent answer: react-native 0.71 is somewhat agnostic about gem vs brew to install cocoapods and just states that "you can install it using the version of Ruby you configured with in the previous steps" https://reactnative.dev/docs/environment-setup#cocoapods Homebrew is however used to install other tools, I haven't found a reasoning behind that choice. – timotgl Jun 13 '23 at 14:51
0

Answers:

  1. In general sudo is not good idea (not recommended). One should not do it, i.e. if your system get stolen and/or get compromised. Cocoapods comes from a trusted source, so people usually tend to install cocoapods gem on root level. Which is what essentially sudo does.
  2. brew is package manager for macOS and brew cask takes it a bit further. It makes the process of installing and updating apps (like: Skype, Chorome) more elegant and smooth. On this question you can read short and comprehensive replies from bfontaine and cellepo.
Waleed Mahmood
  • 1,356
  • 12
  • 13