简体   繁体   中英

Cannot install Pods in iOS Project

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

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

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.

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.

Try this

$sudo gem install cocoapods

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM