Error installing CocoaPods

I am trying to install CocoaPods on my Mac device. When I run the following command:

sudo gem install cocoapods

it returns:

Fetching: cocoapods-core-1.5.3.gem (100%)
Successfully installed cocoapods-core-1.5.3

ERROR:  Error installing cocoapods: invalid gem: package metadata is missing in /Library/Ruby/Gems/2.3.0/cache/cocoapods-deintegrate-1.0.2.gem

What is casing this issue and how do I install CocoaPods?


Solution 1:

I'd recommend using Homebrew to install CocoaPods.

If you are not already using Homebrew, it is a package manager for macOS, hugely popular among developers of all types. It makes installing packages like CocoaPods hassle free.

To install Homebrew, follow the instructions on the homepage

Paste that at a Terminal prompt.

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

Homebrew requires Xcode Command Line Tools to be installed and setup (which I am assuming you already have as you are trying to install CocoaPods, implying you are developing for iOS).

Once Homebrew is setup, simply run:

brew install cocoapods

to install CocoaPods.