How do I install CocoaPods?
Asked Answered
I

30

445

I referred to many links and tried, but I had no success. I read CocoaPods documents and many times tried to install, but I always failed because of the starting steps. I found one error whereby I can't install gems first. What are the steps one by one? Such as steps or a demo of how to install.

This is one link which I tried.

The screenshot refers to this console error I was given:

Enter image description here

Impulsion answered 24/12, 2013 at 4:52 Comment(2)
This is probably related to ruby version, Check version of ruby, ruby -v, what does it says ?Elodea
I think this is the answer for your question check this link #2238840Occultism
I
909

POD Install

  1. Open terminal and type:

    sudo gem install cocoapods
    

    The Gem will get installed in Ruby inside the System library. Or try on Mac OS X v10.11 (El Capitan), type:

    sudo gem install -n /usr/local/bin cocoapods
    

    If there is an error "activesupport requires Ruby version >= 2.xx", then install latest activesupport first by typing in the terminal.

    sudo gem install activesupport -v 4.2.6
    
  2. After installation, there will be a lot of messages. Read them and if no error found, it means the CocoaPods installation is done. Next, you need to setup the CocoaPods master repository. Type in the terminal:

    pod setup
    

    And wait it will download the master repository. The size is very big (370.0 MB in December 2016). So it can be a while. You can track of the download by opening Activity and go to the Network tab and search for "git-remote-https". Alternatively, you can try adding "--verbose" to the command like so:

    pod setup --verbose
    
  3. Once done, it will output "Setup Complete", and you can create your Xcode project and save it.

  4. Then in the terminal, cd to your Xcode project root directory (where your .xcodeproj file resides) and type:

    pod init
    
  5. Then open your project's podfile by typing in terminal:

    open -a Xcode Podfile
    
  6. Your Podfile will get open in text mode. Initially there will be some default commands in there. Here is where you add your project's dependencies. For example, in the podfile, type

    pod 'AFNetworking', '0.9.1'
    

    (This line is an example of adding the AFNetworking library to your project.)

    Other tips:

    Uncomment platform :ios, '9.0'
    Uncomment use_frameworks! if you're using Swift

    When you are done editing the podfile, save it and close Xcode.

  7. Then install pods into your project by typing in terminal:

    pod install
    
    

    or (For m1 chip)

    arch -x86_64 pod install
    

    Depending how many libraries you added to your podfile for your project, the time to complete this varies. Once completed, there will be a message that says

    "Pod installation complete! There are X dependencies from the Podfile and X total pods installed."

    Now close your Xcode project. Then locate and open the .xcworkspace Xcode project file and start coding. (You should no longer open the xcodeproj file.)

Ito answered 12/8, 2014 at 6:6 Comment(7)
'pod install' takes forever. I checked in Activity Monitor > Network tab git-remote-https : Rcvd Packets are very slow, though I have good internet.Battalion
Don't use sudo to install gems. That's a bad habit to be in.Gabel
sudo gem install cocoapods returns ERROR: Loading command: install (LoadError) cannot load such file -- openssl ERROR: While executing gem ... (NoMethodError) undefined method 'invoke_with_build_args' for nil:NilClassSavory
WORTH NOTING you may have to install ruby-2.0.0-p481 I'm using rvm and simply did rvm install ruby-2.0.0-p481 then rvm use ruby-2.0.0-p481 after that the instructions for el Capitan worked like a charm.Jung
pod setup took about 30 min with 15mb internet speed :|Brentwood
could not be much simplerCourbet
NEVER EVER install with SUDO. Never do this, you will get in troubleRingent
M
73
  1. First open your terminal

  2. Then update your gem file with command

    sudo gem install -n /usr/local/bin cocoapods
    
  3. Then give your project path

    cd /your project path
    
  4. Touch the podifle

    touch podfile
    
  5. Open your podfile

    open -e podfile
    
  6. It will open a podfile like a text edit. Then set your target. For example if you want to set up Google maps then your podfile should be like

    use_frameworks!
    target 'yourProjectName' do
        pod 'GoogleMaps'
    end
    
  7. Then install the pod

    pod install
    
Midgard answered 25/9, 2016 at 6:12 Comment(1)
I got the below error after "pod install" :( [!] Invalid Podfile file: [!] Unable to locate the executable node. # from /Users/{user}/Documents/GitHub/ActivityList/ios/Podfile:45 # ------------------------------------------- # # react-native-cli autolinking > use_native_modules! # end # -------------------------------------------Cantillate
M
67

On macOS v10.14 (Mojave) with Xcode 10.3, I got scary warnings from the gem route with or without -n /usr/local/bin:

xcodeproj's executable "xcodeproj" conflicts with /usr/local/bin/xcodeproj
Overwrite the executable? [yN]

What works for me is still Homebrew. Just:

brew install cocoapods
Miley answered 20/8, 2019 at 3:9 Comment(5)
This indeed worked for me. And it was pretty straightforward. I tried the sudo gem install, did not seem to work for me.Mantilla
Tried sudo gem install but didn't work. Tried sudo gem install -n /usr/local/bin cocoapods but still no luck. But tried brew install cocoapods and boom everything right on the track.Jockstrap
How should one deal with this scary warning? I think the warning exists because you already have the homebrew version of cocoapods installed. Homebrew executables are usually located in usr/local/binReactionary
Homebrew worked on Catilina as well, like a charm.Poncho
Is it possible to install a specific version of cocoapods with brew? brew install [email protected] doesn't work :(Euclid
T
48

This works for Mac OS X v10.11.x (El Capitan)

sudo gem install -n /usr/local/bin cocoapods

After this, you can set up the pod using pod setup cmd and then move to your project directory and install pod.

Tubule answered 26/12, 2015 at 5:56 Comment(4)
@Jayesh For me this was the only one worked... and you saved my day... :)Duncandunce
@Duncandunce i take 2 day's for solving pod problem.. :)Tubule
First you need follow step of @Om Prakash AnswerTubule
Am I correct in saying that for the first step when you call "pod setup", you can be in any directory and don't have to be in your actual project directory to do the pod setup?Praiseworthy
L
23

Simple steps to install a pod file:

  1. Open the terminal

  2. Command on the terminal: sudo gem install cocoapods

  3. Set your project path in the terminal.

  4. Command: pod init

  5. Go to the pod file of your project and add the pod which you want to install

  6. Added in the pod file: pod 'AFNetworking', '~> 3.0

  7. Command: Pod install

  8. Close the Xcode project

  9. open your project from the terminal

  10. Command: open PodDemos.xcworkspace

Lated answered 9/3, 2018 at 11:46 Comment(1)
Why the rollback? It's easier to understand with the correct formatting.Snowwhite
T
16

Year 2020, installing CocoaPods v1.9.1 in macOS v10.15 (Catalina)

  1. First set up your Xcode version in your Mac using the terminal.

    sudo xcode-select -switch /Applications/Xcode.app
    
  2. Next, install CocoaPods using the terminal.

    sudo gem install cocoapods
    

For more information, visit the official website, https://cocoapods.org/.

Transilluminate answered 21/5, 2020 at 7:26 Comment(0)
V
15

These are the complete steps that I usually follow. I am posting these steps as short as possible and assuming that you know about Mac and Xcode projects. First of all, open the terminal and use the following commands, and press enter after each command.

Type in the following command if you don't already have CocoaPods installed:

sudo gem install cocoapods

Now please move to your Xcode Project directory by using this following command, and replace /Your Xcode Project Directory Path with the actual path to the directory:

cd /Your Xcode Project Directory Path

Below are instructions for how to use CocoaPods. Please wait for some time after each and every command entered to the terminal to execute successfully.

  1. Searching for pods in terminal:

    pod search networking (replace networking with which you want to search)

  2. Creating the pod file:

    pod init

  3. Opening the pod file:

    open -a Xcode Podfile

  4. Adding the pods: (After adding your pods you must save the podfile first and then head back to the terminal again.)

    target 'WebServiceUsingMantleAFNetworking' do
    # platform :ios, '8.0' //Choose your version of iOS
    pod 'AFNetworking', '~> 2.6.0’
    
    end
    

    OR

    platform :ios, '8.0'
    pod 'AFNetworking'
    pod 'Mantle'
    pod 'LBBlurredImage'
    pod 'TSMessages'
    pod 'ReactiveCocoa'
    
  5. Installing the pods:

    pod install

  6. Check for updates of pods on existing project:

    pod outdated

  7. Update the existing pods:

    pod update

  8. Uninstall the Cocoapods from system:

    sudo gem uninstall cocoapods

    There is a complete tutorial for removing pods from your Xcode project on Stack Overflow. You can check on this following link for more info.

    How to remove CocoaPods from a project?

Venable answered 3/10, 2015 at 10:56 Comment(0)
D
11

Here are all steps with an image. Please follow it properly and I am sure you will not get any error.

From How to install CocoaPods and setup with your Xcode project.


First of all, check you have to install command line or not.

You can check this by opening Xcode, navigating the menu to

Xcode → PreferencesDownloadsComponents. Find Command Line Tools and select install/update.

Commandline tool

If you haven't found command line tool then you need to write this command in the terminal:

xcode-select --install

And click on install.

If you have installed the command-line tool, you need to select your Xcode directory (sometimes these type of problems created due to different versions of Xcode available)

Follow this procedure.

Open terminal and run this command:

sudo gem install cocoapods

Enter the admin password. This could take a while. After a few minutes, it will show a green message if CocoaPods installed successfully in your Mac machine.

If you are getting any error with Xcode 6 like developer path is missing. First run this command in terminal:

sudo xcode-select -switch /Applications/Xcode6.app (or your XCodeName.app)

Now you can set up Pod with your Xcode project.

And now you have to install pod. Follow this procedure.

  1. Open Terminal

  2. Change directory to your Xcode project root directory (where your ProjectName.xcodeproj file is placed).

  3. pod setup: (Setting up the CocoaPods master repository)

If successful, it shows: Setup completed (read-only access). So, you set up everything. Now let’s do something which is more visible…Yes! Let’s install libraries in your Xcode project.

Now you have to set up and update the library related to pod in your project.

Steps to add-remove-update libraries in pod:

  1. Open Terminal

  2. Change directory to your Xcode project root directory. If your terminal is already running then there isn't any need to do this, as you are already at the same path.

  3. touch pod file

  4. open -e podfile (This should open a blank text file)

  5. Add your library names in that text file. You can add new names (library name), remove any name or change the version, e.g.:

    pod ’Facebook-iOS-SDK’
    pod ’EGOTableViewPullRefresh’
    pod ’JSONKit’
    pod ‘MBProgressHUD
    

NOTE: Use the (control + ) button to add single quote at both end of library name. It should be shown as straight vertical line. Without control button it shall be added as curly single quote which will give error while installation of file.

  1. Save and close this text file. Now libraries are set up and you have to install/update it

  2. Go to your terminal again and run this command: pod install (to install/update these libraries in pod).

You should see output similar to the following:

Updating spec repo `master’ \
Installing Facebook-iOS-SDK \
Generating support files

Setup completed.

Note:

If you have followed this whole procedure correctly and step by step, then you can directly fire the pod update command after selecting Xcode and then select your project path. And write your command pod update.

You can also check a command line tool here:

Command line tool in Location

Dualistic answered 18/9, 2015 at 2:0 Comment(1)
When you quote someone else's work, please use quote formatting to indicate what has been copied (it is a little dishonest not to). Additionally, it is more honest to state up-front the source link where the copied text comes from, instead of at the bottom of your answer.Wondering
D
11
  1. Open Terminal
  2. Type in sudo gem install cocoapods if you don't have CocoaPods
  3. Enter cd /project path, but replace project path with actual project path
  4. touch podfile
  5. Use one of the following commands to open the podfile: open -e podfile to open in TextEdit or open -a pod file to open in Xcode
  6. Set your target and add pod file of GoogleMaps like as:
    target 'PROJECT NAME HERE' do
    pod 'GoogleMaps'
    end
    
  7. Use pod install to install dependencies
Disquiet answered 8/4, 2017 at 10:26 Comment(1)
thanks for sharing! Didn't know I can open a document inside a seperate window or in xCode through the bash! :)Tit
L
10

On mac M1 I had two cocoapods installed, one was using brew and one with gem. With 2 different versions. After reading many of your posts, and try many things I encountered various troubles.

Finally this one help me : thanks to Evan

With his post : https://mcmap.net/q/81687/-you-may-have-encountered-a-bug-in-the-ruby-interpreter-or-extension-libraries

The final working sequence for me probably was :

  • sudo gem uninstall cocoapods
  • brew uninstall cocoapods
  • brew install cocoapods
  • brew reinstall ruby
  • => RESTART ALL TERMS <= magical step, thank you Evan
  • cd myProj
  • pod install
Lieb answered 14/2, 2022 at 15:59 Comment(1)
Thanks! These steps helped me clean up my environment. I looks like I had it installed via both gem and brew.Midgut
D
9

CocoaPods Installation on macOS v10.13 (High Sierra):

  1. Install Homebrew - https://brew.sh/

  2. Execute the following commands in the terminal:

    sudo gem update --system
    sudo gem install activesupport -v 4.2.6
    
    sudo gem install -n /usr/local/bin cocoapods
    
    pod setup
    
    pod setup --verbose
    
Depersonalize answered 24/8, 2018 at 8:26 Comment(0)
R
9

For macOS v10.15 (Catalina):

sudo gem install -n /usr/local/bin cocoapods -v 1.8.4

The latest CocoaPods 1.10.0 seem not to be working.

I found the answer in Trouble with installing CocoaPods.

Roseleeroselia answered 2/3, 2021 at 17:46 Comment(0)
S
8

1- Install the Cocoapods in your machine

$ sudo gem install cocoapods

$ pod setup --verbose

2- Check whether Cocoapods is installed on your machine or not?

$ pod --version

3- Go to your project directory where .xcodeproj is present

$ pod init
  • After using pod init one additional file is added in your folder of name Podfile.

4- By double click open the podfile and pods between target and end

5- Install Pod using command

pod install
  • When you run the pod install command it installs all pods which you write in the pod file. And after you install the required commands open the project directory you get 2 new files.

First is Podfile.lock -> Every time the pod install command is run — and downloads and install new pods — it writes the version it has installed, for each pod, in the Podfile.lock file.

Second is .xcworkspace -> Xcode workspace files can be used as a wrapper or container for an Xcode .XCODEPROJ project.

Now use your library by using .xcworkspace which have a white background colour.

Seleneselenious answered 22/1, 2022 at 9:14 Comment(0)
A
7

Pod installation giving an error on Mac OS X v10.11.2 (El Capitan):

ERROR: Error installing cocoapods:
activesupport requires Ruby version >= 2.2.2.

Enter image description here

After getting this error, I tried this command and installed again. It worked for me.

sudo gem install activesupport -v 4.2.6

Now try the same pod installation command

sudo gem install -n /usr/local/bin cocoapods
Adulterine answered 27/8, 2016 at 6:55 Comment(0)
R
6

For me, the easiest way was to install via a Ruby gem:

sudo gem install cocoapods -v

Please note -v for verbose. It takes a while to install CocoaPods and often you get confused if it's really happening.

Resilience answered 3/5, 2016 at 9:6 Comment(0)
W
6

You can install CocoaPods via Homebrew in macOS.

First, open your terminal, and run this code (for installing Homebrew if you have not): Go here for the latest command.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then install CocoaPods easily via this command:

brew install cocoapods
Worshipful answered 24/4, 2019 at 15:3 Comment(0)
B
6
sudo gem install -n /usr/local/bin cocoapods

This worked for me. -n helps you fix the permission error.

Brentonbrentt answered 26/9, 2019 at 21:5 Comment(0)
A
5

Pod File Install Steps

sudo gem install -n /usr/local/bin cocoapods

Pod setup

cd ~/Path/To/Folder/Containing/ShowTracker

touch podfile
open -a Xcode Podfile // To open it in Xcode
OPEN -e podfile       // To open it in text editor
pod install           // To install a new pod
pod update            // To update all pods
Anatolian answered 17/5, 2016 at 5:37 Comment(0)
S
5

Works in macOS Big Sur

1 install LATEST version of brew (https://treehouse.github.io/installation-guides/mac/homebrew)

2 then use "brew uninstall cocoapods"

3 install the latest version of cocoapods using "brew install cocoapods" (You must verify installed version with github version https://github.com/CocoaPods/CocoaPods/releases/tag/1.11.2, they must match)

4 overwrite link to cocoapods with "brew link --overwrite cocoapods"

5 check the version of cocoapods "pod --version"

6 done, You have the latest version of cocoapods installed

Silkworm answered 7/12, 2021 at 16:50 Comment(0)
L
4

If you behind a proxy then pass the proxy as an argument:

sudo gem install --http-proxy http://user:[email protected]:80 cocoapods
Lipchitz answered 24/12, 2013 at 11:10 Comment(0)
R
4

Normally we use

sudo gem install cocoapods

Solution, fix for CocoaPods error on Mac OS X v10.11 (El Capitan):

sudo gem install -n /usr/local/bin cocoapods
pod setup
cd /project path
pod init

In Podfile we need to set the target

# Podfile

platform :ios, '9.0'

use_frameworks!

# My other pods

target “Projectname” do

    pod 'MBProgressHUD', '~> 0.8'
    pod 'Reachability', '~> 3.1.1'
    pod 'AFNetworking', '~> 2.2'
    pod 'TPKeyboardAvoiding', '~> 1.2'

end

target 'ProjectnameTests' do
    testing_pods
end

target 'ProjectnameUITests' do
    testing_pods
end

In the console - terminal

pod install
Rettke answered 26/5, 2016 at 10:53 Comment(0)
H
3

CocoaPods installation step:

Open your Terminal:

sudo gem update --system

sudo gem install activesupport -v 4.2.6

sudo gem install cocoapods

pod setup

pod setup --verbose

Then go to your project directory with Terminal:

cd Your Project Path

Then enter the below command in Terminal:

pod init

open -a Xcode Podfile

(Edit POD file with pod ‘libname’)

pod install
Huber answered 4/3, 2016 at 6:18 Comment(1)
Missing steps for El Capitan OS: sudo gem install cocoapods (which will throw errors by default) neonichu @ GitHub: This is the solution when you are receiving the "Operation not permitted" error. $ mkdir -p $HOME/Software/ruby $ export GEM_HOME=$HOME/Software/ruby $ gem install cocoapods [...] 1 gem installed $ export PATH=$PATH:$HOME/Software/ruby/bin $ pod --version 0.37.2 For details - github.com/CocoaPods/CocoaPods/issues/3692Suppositive
C
3

Thanks to SwiftBoy's 10-step solution I successfully used CocoaPods to setup the latest version of AudioKit.

1. Using Xcode create MyAudioApp Swift project saving it to my Developer directory e.g.

    /Users/me/Developer/MyAudioApp

2. Using Cocoapods install AudioKit within MyAudioApp project (i.e. install AudioKit sdk)

3. Open Terminal, type command below and press Enter

    sudo gem install -n /usr/local/bin cocoapods

4. Provide system password and press Enter

5. In Terminal, type command below and press Enter

    cd /Users/me/Developer/MyAudioApp

6. Create project pod file - in Terminal type command below and press Enter

    touch Podfile

7. Open project pod file - in Terminal type command below and press Enter (opens in TextEdit)

    open Podfile

8. Edit code below into open pod file (and save file before quitting TextEdit)

    source 'https://github.com/CocoaPods/Specs.git'
        platform :ios, '12.2'
        use_frameworks!

        target 'MyAudioApp' do
        pod 'AudioKit', '~> 4.7'
    end

9. To install AudioKit in MyAudioApp workspace type Terminal command below and press Enter

    Pod install     

and wait for install to finish

10. In Finder, go to project folder /Users/me/Developer/MyAudioApp and click .xcworkspace file below (opens in Xcode!)

    /Users/me/Developer/MyAudioApp/MyAudioApp.xcworkspace

11. In MyAudioApp edit ViewController.swift and insert the following

    import AudioKit 
Copenhagen answered 2/6, 2019 at 12:52 Comment(0)
Y
2

For CocoaPods in the terminal, follow this:

sudo gem update

sudo gem install cocoapods

pod setup

cd (project direct drag link)

pod init

open -aXcode podfile # (If it’s already open, add your pod file name. Example: alamofire4.3)

pod install

pod update
Youngman answered 16/1, 2018 at 18:30 Comment(0)
R
1
  1. Open Terminal
  2. Enter $ sudo gem install cocoapods command in terminal
  3. Create new Xcode project
  4. Navigate to directory containing Xcode project. Use cd “../directory-location/..” or cd [drag-and-drop project folder]
  5. Pod install

Screenshot for steps

If this prompts error Unable to add a source with url.. then install command line tool for Xcode. Again, rerun Pod install command.

This will install all dependencies as well.

Now, open your project in Workspace i.e. Project-Name.xcworkspace rather than Project-Name.xcodeproj

Rupiah answered 14/7, 2015 at 12:11 Comment(0)
D
1

If you want to install CocoaPods for the first time for your project.

Example: Here we will install the "Alamofire" SDK using CocoaPods step by step.

Step 1. Open Terminal, hit command, and then press the Enter key

sudo gem install cocoapods

Step 2. If it asks, you should provide system password and then press the Enter key

Step 3. With command “cd” and give the path of your project and then press the Enter key

Note: type the "cd" command then space and drag the project folder to the terminal. It will take the project path as shown below (here my project name is: Simple Alamofire)

cd  /Users/ramdhanchoudhary/Documents/Swift\ Workspace/Simple\
Alamofire

Enter image description here

Step 4. Create a pod file in your project by terminal by command “touch Podfile” and press “Enter”

touch Podfile

Step 5. Then, open “Podfile” by terminal command “open Podfile” and press “Enter”

open Podfile

Step 6. Now type following code in opened pod file then save and close file

source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '10.0'
    use_frameworks!

    target '<Your Target Name>' do
            pod 'Alamofire', '~> 4.0'
    end

Step 7. Back in Terminal type command “Pod install” and then press Enter Key.

Pod install

Step 8. Wait for the install to get complete 100% its around 650+ MB

Step 9. That's it goto project folder and open below file

<your project name>.xcworkspace

Step 10. Import Alamofire class and use!!

import Alamofire
Donegal answered 30/5, 2019 at 9:53 Comment(0)
O
0

Check this

gem install -p http://proxy_ip:proxy_port compass

You might need to add your user name and password to it:

gem install -p http://[username]:[password]@proxy_ip:proxy_port compass

And check this link it may help you.

Occultism answered 18/10, 2014 at 11:54 Comment(0)
J
0

For Mac OS X v10.11 (El Capitan)

rvm install ruby-2.2.2.

rvm use ruby-2.2.2.

sudo gem install -n /usr/local/bin cocoapods

Jung answered 1/6, 2017 at 3:8 Comment(0)
I
0

I was facing the same problem in mac after updating to macOS 12.1 Also you might get error attached with Ruby framework installed on your mac machine.

  • You just need to remove cocoa pods completely from mac and re-install cocoapods

  • And then reinstall your project pods

This will solve your problem

Ireful answered 24/1, 2022 at 13:16 Comment(0)
W
0

for Apple Silicon Mac

$ sudo gem uninstall ffi && sudo gem install ffi -- --enable-libffi-alloc
Wychelm answered 19/10, 2022 at 9:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.