528

I'm having some issues installing Alamofire 4.0 into my project.

I've got the latest version of Xcode, running Swift 3, and when I try to install alamofire I'm getting like 800 compiler errors.

Apparently

CocoaPods 1.1.0+ is required to build Alamofire 4.0.0+

[!] some_cocoapod requires CocoaPods version >= X.Y.Z, which is not satisfied by your current version, Z.Y.X.

I looked at the version of CocoaPods I have in terminal and it says I'm at 1.0.1.

Running an update didn't work I guess because CocoaPods 1.1 is in beta.

So I'm not exactly sure how to update it up to where I'm good to go. Unless being out of date doesn't force like 800 compiler errors? Does that sound like some other issue?

HangarRash
  • 7,314
  • 5
  • 5
  • 32
Barkley
  • 6,063
  • 3
  • 18
  • 25

22 Answers22

1041

Execute the following on your terminal to get the latest stable version:

sudo gem install cocoapods

Add --pre to get the latest pre release:

sudo gem install cocoapods --pre

If you originally installed the cocoapods gem using sudo, you should use that command again.

Later on, when you're actively using CocoaPods by installing pods, you will be notified when new versions become available with a CocoaPods X.X.X is now available, please update message.

Sampath D
  • 10,494
  • 1
  • 13
  • 8
168

Open the Terminal -> copy below command

sudo gem install cocoapods

It will install the latest stable version of cocoapods.

after that, you need to update pod using below command

pod setup

You can check pod version using below command

pod --version
Dheeraj D
  • 4,386
  • 4
  • 20
  • 34
151

If you are using Homebrew, open terminal and type:

brew upgrade cocoapods

If that does not work, try:

brew install cocoapods

After that, run:

brew link --overwrite cocoapods
Boken
  • 4,825
  • 10
  • 32
  • 42
Sanzio Angeli
  • 2,872
  • 1
  • 16
  • 30
  • 7
    is it possible that the homebrew version is sometimes behind the gem version? – swalkner May 26 '20 at 11:33
  • 5
    It is possible, im getting 1.9.1 while the latest on gem is 1.9.3 – BananZ Jun 05 '20 at 01:54
  • 3
    I am also getting the message "cocoapods 1.9.1 already installed" though the version seems to be 1.9.3 @BananZ did you manage to resolve this? – anoop4real Jun 16 '20 at 13:14
  • 1
    Nope, as the change is minimal, i just ignore the warning -> 'https://github.com/CocoaPods/CocoaPods/releases' and 'https://github.com/CocoaPods/Core/compare/1.9.1...1.9.3'. Anyways I have just checked, latest 1.9.3 is available in homebrew now..'https://github.com/Homebrew/homebrew-core/pull/55646'. If you are interested you may try to contribute to Brew for future upgrades (I have never done it but will try soon in near future). – BananZ Jun 22 '20 at 07:57
  • 1
    My issue was in linking part `brew link --overwrite cocoapods` now problem solved thanks – Ahmed Wahba Jan 13 '22 at 10:29
  • 1
    Make sure pod --version has the same version as the expected Cocoapods installation – OhadM Jun 26 '23 at 14:54
118

If you got System Integrity Protection enabled or any other permission write error, which is enabled by default since macOS Sierra release, you should update CocoaPods, running this line in terminal:

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

After installing, check your pod version:

pod --version

You will get rid of this error:

ERROR:  While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory

And it will install latest CocoaPods:

Successfully installed cocoapods-x.x.x
Parsing documentation for cocoapods-x.x.x
Installing ri documentation for cocoapods-x.x.x
Done installing documentation for cocoapods after 4 seconds
1 gem installed
x0 z1
  • 1,704
  • 1
  • 9
  • 12
37

For those with a sudo-less CocoaPods installation (i.e., you do not want to grant RubyGems admin privileges), you don't need the sudo command to update your CocoaPods installation at all:

gem install cocoapods

You can find out where the CocoaPods gem is installed with:

gem which cocoapods

If this is within your home directory, you should definitely run gem install cocoapods without using sudo.

Finally, to check which CocoaPods you are currently running type:

pod --version
Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
24

I had to do this, was stuck on 1.9.1 on macOS

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

TpoM6oH
  • 8,385
  • 3
  • 40
  • 72
  • 4
    this one “actually” helped! Thanks. :) +1 – TheAlienMann Aug 24 '21 at 22:49
  • Regardless of what I tried, including a few other suggestions here, this is the only one that worked for me. In my specific case I was on Big Sur 11.6 and stuck on Cocoapods 10.1. – xdeleon Oct 02 '21 at 21:41
18

Below are steps to update cocoapods :

  1. Open terminal (Shortcut : Press cmd + space tab to open Spotlight then text in terminal)
  2. Use command sudo gem install cocoapods. This will ask for system password due to security concern thereafter it installs gems

Screenshot 1

  1. Now, set up pod using pod setup command. This will setup cocoapods master repo.

Screenshot 2

  1. You can check the version of cocoapods using pod --version command.

Screenshot 3

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
16

Non of the above solved my problem, you can check pod version using two commands:

  1. pod --version
  2. gem which cocoapods

In my case pod --version always showed "1.5.0" while gem which cocopods shows Library/Ruby/Gems/2.3.0/gems/cocoapods-1.9.0/lib/cocoapods.rb. I tried every thing but unable to update version showed from pod --version. sudo gem install cocopods result in installing latest version but pod --version always showing previous version. Finally I tried these commands:

  1. sudo gem update
  2. sudo gem uninstall cocoapods
  3. sudo gem install cocoapods
  4. pod setup``pod install

The catch for me was sudo gem update. Hopefully it will help any body else.

SeanMC
  • 1,960
  • 1
  • 22
  • 33
Muhammad Ali
  • 587
  • 5
  • 9
13

You can solve this problem by these Commands:

First:

sudo gem install cocoapods

Desp: type user mac password now your cocoapods will be replace with a stable version.

You can find out where the CocoaPods gem is installed with:

gem which cocoapods

if you have cloned the repo then type this command:

pod repo update

close your xcode and run this command

Pod install
Kashif Ahmed
  • 803
  • 9
  • 20
9

If this

sudo gem install cocoapods

gives you this error:

Could not find a valid gem 'cocoapods' (>= 0) in any repository

Try this:

sudo gem install cocoapods --source http://rubygems.org
Arjun
  • 1,477
  • 1
  • 13
  • 23
8

This is a really quick & detailed solution

Open the Terminal and execute the following to get the latest stable version:

sudo gem install cocoapods

Add --pre to get the latest pre release:

sudo gem install cocoapods --pre

Incase any error occured

Try uninstall and install again:

sudo gem uninstall cocoapods
sudo gem install cocoapods

Run after updating CocoaPods

sudo gem clean cocoapods

After updating CocoaPods, also need to update Podfile.lock file in your project.

Go to your project directory

pod install
8

Very Smoot and Easy Solution

//MARK: -Latest stable version:
sudo gem install cocoapods --pre 

//MARK: -If not work then
sudo gem install cocoapods --pre -n /usr/local/bin

//MARK: - if upper command not works you can use below mention command as well!
brew install cocoapods

brew upgrade cocoapods

brew link cocoapods
Shakeel Ahmed
  • 5,361
  • 1
  • 43
  • 34
6

I tried updating and it didn't work. Finally , I had to completely remove (manually )cocoapods, cocoapods-core , cocoapods-try.. and any other package used by cocoapods. Use this terminal command to list all the packages:

gem list --local | grep cocoapods

After that , I also deleted ./cocoapods folder from the user's root folder.

gbenroscience
  • 994
  • 2
  • 10
  • 33
supersabbath
  • 364
  • 3
  • 8
5

After trying all the steps above, with nothing working, I ran bundle update which seems to have done the trick for me.

JackDev
  • 4,891
  • 1
  • 39
  • 48
3

Refer this link https://guides.cocoapods.org/using/getting-started.html

brew install cocoapods

brew upgrade cocoapods

brew link cocoapods

enter image description here

enter image description here

Keshav Gera
  • 10,807
  • 1
  • 75
  • 53
2

I had the problem in myproject when pod version and gem which cocoapods always return difference version.

All I had to do is remove Gemfile.lock in my project and bundle install again. It removed the locked cocoapods version and install a newer one.

Hope that helps some one here.

d2luu
  • 69
  • 6
2

If you updated sudo gem install cocoapods but it's still showing the old version you just need to type bundle update in your terminal to update the bundle and pod --version will show the newest version you installed

candyline
  • 788
  • 8
  • 17
1

Using Bundler?

Run bundle update cocoapods

mintymuz
  • 262
  • 2
  • 14
0

On my M1 Mac, I had a separate version of Homebrew installed for the Silicon/Arm64 side.

brew upgrade cocoapods was defaulting to a rosetta install of homebrew. I kept running it, and couldn't figure out why cocoapods was not updating. So I had to run it in a way that targets the M1 side of things instead of Rosetta.

I had previously aliased the Arm brew to mbrew. So I had to run mbrew upgrade cocoapods

SeanMC
  • 1,960
  • 1
  • 22
  • 33
-1

write on your terminal this: sudo gem install cocoapods --pre

for update the gem of cocoapods to lastest version

-3

First check cocoapods versionlike

pod --version

then update like

sudo gem install cocoapods --pre

after update you can also check cocoapods version.

enter image description here

timbre timbre
  • 12,648
  • 10
  • 46
  • 77
-6

I change the line "pod 'Alamofire', '~> 4.0'" to "pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire', :commit => '3cc5b4e'" after that in terminal: "pod install --repo-update" and it works.