CocoaPods安装

首先,安装好Xcode,并且保证已经安装Xcode Command Line Tool!(新建工程可以看到是否安装)打开终端,在终端输入:xcode-select--install 。就可以安装Xcode Command Line Tool。接着安装homebrew,官网(homebrew)有如何安装的方法,并介绍其作用。但是下载和更新速度太慢,让人极度不舒服,所以推荐在国内自动安装Homebrew的脚本。打开终端,并将这段脚本复制到终端:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

在终端中会看到:

运行后可以看到,共有 4 个下载源可供选择,这时输入选择下载源的序号即可。接下来按照要求输入即可,会很慢,慢慢等,直到显示成功。


      homebrew安装成功后, 打开终端:

1、查看当前Ruby版本

执行:

ruby -v

执行结果:

ruby 2.6.3p62(2019-04-16 revision 67580)[universal.x86_64-darwin20]

2、升级Ruby环境,首先需要安装rvm

执行:

1). curl -L get.rvm.io | bash -s stable

2).source ~/.bashrc

3).source ~/.bash_profile

a1@iirabibideMBP ~ % curl -L get.rvm.io | bash -s stable

  % Total    % Received % Xferd  Average Speed  Time    Time    Time  Current

                                 Dload  Upload  Total  Spent    Left  Speed

100  194  100  194    0    0    171      0  0:00:01  0:00:01 --:--:--  172

  0    0    0    0    0    0      0      0 --:--:--  0:00:01 --:--:--    0

curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 14 ms: Couldn't connect to server

a1@iirabibideMBP ~ % source ~/.bashrc

source: no such file or directory: /Users/a1/.bashrc

a1@iirabibideMBP ~ % source ~/.bash_profile

source: no such file or directory: /Users/a1/.bash_profile

a1@iirabibideMBP ~ %

按照123步执行,第1步会久一些,如果能够一步一步执行,那你的运气真好。但有时候会出现问题:

curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused

解决办法可以参考:解决问题的参考。既然是参考,有时候并不管用,另一种办法在百度云网盘中:链接,提取码:vn3h。在下载得到的文件夹中打开文件bin,然后运行文件:rvm-installer。终端会进入下载状态,然后提示“.....[进程已完成]”即成功安装rvm。

重点1来了:重启终端

3、查看rvm版本

rvm -v

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

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

4、列出ruby可安装的版本信息

rvm list known

显示如下

[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[.8]

[ruby-]2.4[.10]

[ruby-]2.5[.8]

[ruby-]2.6[.6]

[ruby-]2.7[.2]

[ruby-]3[.0.2]

ruby-head

.....

5、选择其中一个版本安装(比如:3.0.2)

rvm install 3.0.2

然后也是等待,还有点久那种

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

6、设置为默认版本

rvm use 3.0.2 --default

7、更换源

sudo gem update --system

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

gem sources --add https://gems.ruby-china.com/

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

gem sources -l

如果是以下结果则说明正确,如果有其他那就百度吧:

***CURRENT SOURCES***

https://gems.ruby-china.com/

9、这时候才正式开始安装CocoaPods

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

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

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

11、安装本地库

pod setup

注意:在MacOS Catalina系统命令行执行pod setup命令后,很快就结束了。这时候别以为已经完成。接下来需要手动安装本地库。

12、安装本地库

在终端继续执行:

git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk

使用这个命令执行等待一段时间之后大有可能会失败,最大原因是网络问题。推荐使用国内镜像:

git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk

13、下载安装完成之后可执行下列命令检查是否可用(第一次使用退出终端,重新开起终端)

pod search AFNetworking

按照这些步骤,基本上可以成功安装CocoaPods了,当然还会有意外,各种问题,如果再不幸,自己摸索吧,你遇到的问题,别人也会遇到,所以别慌。

作者:黄彦祖学长

链接:https://www.jianshu.com/p/a60f878bf055

来源:

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

你可能感兴趣的:(CocoaPods安装)