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


Solution 1:

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 user_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
    

    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.)

Solution 2:

  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
    

Solution 3:

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.

Solution 4:

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

Solution 5:

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