CocoaPods的安装、使用及常见的问题

一、安装cocoapods

1、查看gem源

gem sources -l

2、切换gem源

remove后边是gem sources -l显示的当前gem源,如果已经是https://gems.ruby-china.org/,可跳过此步。

gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/

3、安装cocoapods

sudo gem install cocoapods

也可以安装到指定路径:

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

二、可能出现的报错信息

1、没有权限

ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

解决方案:命令前加sudo。

2、gem版本太老

ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/update_rubygems

解决方案:下载最新版gem,解压,进入目录

sudo ruby setup.rb

使用以下命令安装pod

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

3、pod update卡住不动

解决方案

pod update --verbose --no-repo-update

4、ruby环境太老

ERROR: SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR: You must add /C=IL/O=StartCom Ltd./OU=Secure Digital Certificate Signing/CN=StartCom Certification Authority to your local trusted store
ERROR: SSL verification error at depth 2: self signed certificate in certificate chain (19)
ERROR: Root certificate is not trusted (/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA)

需要更新ruby到2.2以上。

1、安装rvm
curl -sSL https://get.rvm.io | bash -s stable
2、装载rvm

source ~/.rvm/scripts/rvm
3、修改rvm下ruby的源
echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db
4、查看支持的ruby版本
rvm list known
5、安装ruby 2.4
rvm install 2.4.0
6、设置2.4为默认
rvm use 2.4.0 --default

5、SSL证书问题

error: RPC failed; curl 56 SSLRead() return error -9806/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

Failed during: git fetch origin master:refs/remotes/origin/master --tags --force --depth=1

使用以下命令忽略报错信息

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

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

6、pod setup缓慢,几乎不动

fatal: unable to access 'https://github.com/CocoaPods/Specs.git/': SSLRead() return error -9806

使用国内镜像

cd ~/.cocoapods
git clone https://code.aliyun.com/Magi/CocoaPods.git master

7、rvm install ruby 报错

Error running '__rvm_make install',
showing last 15 lines of /Users/用户名/.rvm/log/1494312229_ruby-2.4.0/install.log

查看install.log找到具体原因

Referenced from: /Users/RenChao/.rvm/src/ruby-2.4.0/.ext/x86_64-darwin16/openssl.bundle
Reason: image not found - /Users/RenChao/.rvm/src/ruby-2.4.0/.ext/x86_64-darwin16/openssl.bundle

解决方法:安装openssl

rvm pkg install openssl

三、彻底卸载cocoapods

使用卸载命令sudo gem unintall cocoapods失败,需要手动卸载。

1、查看pod命令的路径,并删除

which pod

比如pod命令路径为/usr/local/bin/pod,然后删除

rm -rf /usr/local/bin/pod

2、查看已安装与cocoapods相关的组件

gem list | grep cocoapods

运行结果:

cocoapods-core (1.0.1)
cocoapods-deintegrate (1.0.1)
cocoapods-downloader (1.1.1)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.0.0)
cocoapods-try (1.1.0)

3、依次卸载各相关组件

sudo gem uninstall cocoapods-core
sudo gem uninstall cocoapods-downloader
sudo gem uninstall cocoapods-plugins
sudo gem uninstall cocoapods-search
sudo gem uninstall cocoapods-stats
sudo gem uninstall cocoapods-trunk
sudo gem uninstall cocoapods-try

cocoapods已彻底卸载,需要的话可以重新安装。

你可能感兴趣的:(CocoaPods的安装、使用及常见的问题)