如何安装CocoaPods

2020-08-08  本文已影响0人  Zorin

一、安装

CocoaPods是用Ruby实现的,要想使用它首先需要有Ruby的环境。幸运的是OS X系统默认的已经可以运行Ruby了,因此我们只需要执行以下命令:

sudo gem install cocoapods 

CocoaPods是以Ruby gem包的形式被安装的。在安装执行的过程中,可能会问我们是不是更新rake,输入y即可。这是因为rake gem包会在安装的过程中检查更新,如果有可用的新版本就会出现刚才的选项。

pod setup  

如果没有报错,就说明一切安装就成功了!

二、安装过程中可能遇到的问题

  1. 执行完install命令半天没反应
    这有可能是因为Ruby的默认源使用的是cocoapods.org,国内访问这个网址有时候会有问题,网上的一种解决方案是将远替换成淘宝的,替换方式如下:
gem sources --remove https://rubygems.org/ 
//等有反应之后再敲入以下命令  
$ gem sources -a http://ruby.taobao.org/

要想验证是否替换成功了,可以执行:

gem sources

正常的输出是:

*** CURRENT SOURCES ***  
  
http://ruby.taobao.org/  
  1. gem版本过老
    gem是管理Ruby库和程序的标准包,如果它的版本过低也可能导致安装失败,解决方案自然是升级gem,执行下述命令即可:
sudo gem update --system  
  1. 安装完成后,执行pod setup命令时报错:
/Users/wangzz/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:298:in `to_specs': Could not find 'cocoapods' (>= 0) among 6 total gem(s) (Gem::LoadError)  
    from /Users/wangzz/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:309:in `to_spec'  
    from /Users/wangzz/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:53:in `gem'  
    from /Users/wangzz/.rvm/rubies/ruby-1.9.3-p448/bin/pod:22:in `<main>' 

这就是路径设置的问题,可以通过执行:

rvm use ruby-1.9.3-p448  
  1. 权限问题:报以下错误
 Fetching cocoapods-1.9.3.gem
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

使用以下命令: 前面一定要有sudo 表示申请权限

sudo gem install cocoapods
  1. 没有安装到指定目录的权限

在cocoapods 执行

 sudo gem install cocoapods

的时候出现

    You don't have write permissions for the /usr/bin directory.

在终端执行以下命令

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

完美解决

  1. pod search 报错
 CDN: trunk - Cannot perform full-text search because Algolia returned an error: 0: Cannot reach any host: execution expired, execution expired, <br>SSL_connect returned=1 errno=0 state=error: certificate verify failed (unable to get local issuer certificate), execution expired

解决方式:保证Podfile文件头:

source 'https://github.com/CocoaPods/Specs.git'

然后执行:pod repo remove trunk , 再重新pod seach XXX,就可以了!

三、升级CocoaPods

升级很简单,再次执行安装命令即可:

sudo gem install cocoapods 
上一篇下一篇

猜你喜欢

热点阅读