Cocoapods安装过程

1.升级Ruby环境

gem -v

gem update --system

如果没有权限去升级Ruby ?就输入

sudo gem update --system

2.换掉Ruby镜像

首先移除现有的Ruby镜像

gem sources --remove https://rubygems.org/

添加国内最新镜像源

gem source -a https://gems.ruby-china.org/

查看当前镜像

gem sources -l

3.安装CocoaPods

sudo gem install cocoapods

如果报错

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

4.初始化repos文件

pod repo add master https://github.com/CocoaPods/Specs.git

报错用这个

pod setup

5.安装过程中出现报错

报错类型1:

[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress

Cloning into 'master'...

fatal: unable to access 'https://github.com/CocoaPods/Specs.git/': Could not resolve host: github.com

原因可能是:github.com没有被主机给解析

解决方法:在本地手动指定github.com的IP地址

编辑文件etc/hosts

sudo vi /etc/hosts

添加github的地址

::1             localhost

192.30.255.112  github.com

报错类型2:

[!] /usr/bin/git clone 'https://github.com/CocoaPods/Specs.git' master --depth=1

Cloning into 'master'...

fatal: unable to access 'https://github.com/CocoaPods/Specs.git/': Could not resolve host: github.com

原因可能是:安装多个Xcdoexcode路径问题

解决方法:sudo xcode-select -switch /Applications/Xcode.app/

在终端里输入下方命令可以知道Xcode的路径:

xcode-select -p

原文地址:https://www.cnblogs.com/zhou--fei/p/7795811.html