CocoaPods安装

Ruby环境搭建

查看当前Ruby版本

1
ruby -v

查看rvm版本

1
rvm -v 

显示如下(或者是其他版本)

1
rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

列出ruby可安装的版本信息

1
rvm list known

显示如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.7]
[ruby-]2.4[.4]
[ruby-]2.5[.1] // 重点在这里 重点在这里 重点在这里
[ruby-]2.6[.0-preview2] // 测试版
ruby-head
.....

安装一个ruby版本(这里我选择的是2.5.1版本,当然你也可以选择其他的)

1
2
3
rvm install 2.5.1
// 注意:安装过程中需要两次按下 Enter 键, 第二次按下后需要输入电脑访问密码(不可见,只管输入就行);
// 如果你电脑没有安装Xcode和Command Line Tools for Xcode以及Homebrew 会自动下载安装,建议提前安装这三者.

这里很多小伙伴会遇到错误,大部分是因为没有安装Homebrew造成,所以所以所以要提前安装比较好

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

设置为默认版本

1
rvm use 2.5.1 --default

更换源

1
2
3
4
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/

为了验证你的Ruby镜像是并且仅是ruby-china,执行以下命令查看

1
gem sources -l

如果是以下结果说明正确,如果有其他的请自行百度解决

1
2
*** CURRENT SOURCES ***
https://gems.ruby-china.com/

开始安装CocoaPods

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

如果安装了多个Xcode使用下面的命令选择(一般需要选择最近的Xcode版本)

1
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

安装本地库

1
pod setup

执行以上命令后

1
2
3
4
5
6
Setting up CocoaPods master repo
$ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
Cloning into 'master'...
remote: Counting objects: 1879515, done.
remote: Compressing objects: 100% (321/321), done.
Receiving objects: 21% (404525/1879515), 73.70 MiB | 22.00 KiB/

然后就是漫长的等待,当然,网络好的情况下会更快

如果一直安装不成功请参考这里

查看你是否安裝成功

1
pod

显示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Usage:

$ pod COMMAND

CocoaPods, the Cocoa library package manager.

Commands:

+ cache Manipulate the CocoaPods cache
+ deintegrate Deintegrate CocoaPods from your project
+ env Display pod environment
+ init Generate a Podfile for the current directory
+ install Install project dependencies according to versions from a
Podfile.lock
+ ipc Inter-process communication
+ lib Develop pods
+ list List pods
+ outdated Show outdated project dependencies
+ plugins Show available CocoaPods plugins
+ repo Manage spec-repositories
+ search Search for pods
+ setup Setup the CocoaPods environment
+ spec Manage pod specs
+ trunk Interact with the CocoaPods API (e.g. publishing new specs)
+ try Try a Pod!
+ update Update outdated project dependencies and create new
Podfile.lock

Options:

--silent Show nothing
--version Show the version of the tool
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified command

CocoaPods版本

1
pod --version