Skip to main content

Getting Started with Cocoapods

Installation

Built with Ruby, Cocopods is installable with the default Ruby available on macOS.  Using the default Ruby install will require you to use sudo when installing gems.

sudo gem install cocoapods

However, if you attempt to install or update Cocopods without Sudo you will hit a permission issue.

gem install cocoapods

Fetching cocoapods-1.11.2.gem
Fetching cocoapods-core-1.11.2.gem
Fetching rexml-3.2.5.gem
Fetching xcodeproj-1.21.0.gem
Fetching addressable-2.8.0.gem
Fetching molinillo-0.8.0.gem
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

 

Choices

You can either install with sudo, therefore giving RubyGems admin permission.  Or you can do a sudo-less installation.  This is achieved by passing either the --user-install flag to gem install or by configuring the RubyGems environment.  To do the later open up terminal and create or edit your .bash_profile with your preferred editor. Then enter these lines into the file:

export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH

Note that if you choose to use the --user-install option, you will still have to configure your .bash_profile file to set the PATH or use the command prepended by the full path.  Easy enough to find out where a gem is installed with gem which Cocoapods. For example, by using:

$ gem install cocoapods --user-install
$ gem which cocoapods
/Users/{name}/.gem/ruby/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods.rb
$ /Users/{name}/.gem/ruby/2.0.0/bin/pod install

 

Updating CocoaPods

To update CocoaPods you simply install the gem again.  However, with the discussion about sudo-less install above.  If you originally installed the cocoapods gem using sudo, you should use that command again.

sudo gem install cocoapods

sudo gem install cocoapods --pre

 

Related articles

Andrew Fletcher06 May 2020
CDN error on pod update
Today while in Terminal, I ran a regular script pod update.  However, this time I received the following error [!] CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/d/a/2/Alamofire/5.1.0/Alamofire.podspec.json Response: Timeout was...