1

I have been trying to update cocoapod. In between I have updated Ruby and RVM. Now when I try pod init in my new ios project, shows the following

Traceback (most recent call last):  
2: from /usr/local/bin/pod:23:in `<main>'
1: from /usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in `activate_bin_path'
/usr/local/Cellar/ruby/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)

I checked the following,

  1. ruby --version

    ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin16]
    
  2. rvm list rubies

    =* ruby-2.5.1 [ x86_64 ]
    
    # => - current
    # =* - current && default
    #  * - default
    
Holger Just
  • 52,918
  • 14
  • 115
  • 123
Karan Alangat
  • 2,154
  • 4
  • 25
  • 56

7 Answers7

11

Please install cocoapods into /usr/local/bin and not into /usr/bin with this command:

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

And you should remove cocoapods before reinstalling: sudo gem uninstall cocoapods

falsecrypt
  • 1,536
  • 14
  • 11
5

You will probably solve this by installing the cocoapods gem into your current RVM-installed Ruby:

gem install cocoapods

Since you are using RVM, there is no need to ever use sudo for any commands to install or change anything about your Ruby. When installing gems with sudo gem install ..., you are installing it into your system's Ruby installation instead of your RVM Ruby. This can then cause issues in the interaction between the RVM environment and the system Ruby.

Holger Just
  • 52,918
  • 14
  • 115
  • 123
4

I run into same error. But uninstall and sudo gem install -n /usr/local/bin cocoapods did NOT work for me.

So I tried rvm list rubies and found out there's a warning:

Warning! PATH is not properly set up, '/Users/xxx/.rvm/gems/ruby-2.1.3/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-2.1.3'.

I've no idea what's going on so I followed this issue: Warning! PATH is not properly set up, usually this is caused by shell initialization files

I did rvm reset & rvm version. The warning disappeared.

Then I run sudo gem install -n /usr/local/bin cocoapods

This fixed my problem. Post it here in case some one run into similar situation.

GGY
  • 73
  • 1
  • 1
  • 6
0

Try this

$sudo gem install cocoapods

  • Thanks for your reply. I tried to install and got this - Successfully installed cocoapods-1.5.3 Parsing documentation for cocoapods-1.5.3 Done installing documentation for cocoapods after 2 seconds 1 gem installed – Karan Alangat Jul 19 '18 at 06:30
0

If you already has cocoapods installed and you recently deleted or moved the current folder just try re-enter into the path again. Maybe terminal does not know where you are any more. This solved my problem.

orafaelreis
  • 2,855
  • 2
  • 28
  • 31
0

What did work for me I set 'command line tool path' in xcode preferences and was able to install missing pods

Muhammad Awais
  • 340
  • 3
  • 15
-1

Please install cocoapods into /usr/local/bin and not into /usr/bin with this command:

sudo gem uninstall cocoapods
sudo gem install -n /usr/local/bin cocoapods
PLASMA chicken
  • 2,777
  • 2
  • 15
  • 25
Davender Verma
  • 503
  • 2
  • 12