CocoaPods安装方法

全新mac进行cocoapods安装记录与填坑(安装RVM与Homebrew失败)路程

在实际操作中遇到了进度缓慢,中断,失败等问题
参照1 总流程
参照2 安装RVM 此处有坑,仅做参照(可能是我操作有误,后面说明)
参照3 安装Homebrew

cocoapods是啥请忽略~~

cocoapods安装流程

不打开终端是不行滴~

1、查看当前Ruby版本(此处mac默认的ruby版本为2.6.3)

ruby -v

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

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

source ~/.bashrc

source ~/.bash_profile

坑1.此处提示Failed to connect to raw.githubusercontent.com,这时可以进行参照2 安装RVM 的操作,但是打开hosts文件操作命令

cd /etc
vi hosts

似乎有误,至少我尝试是无法保存的,于是进行如下操作:
用程序里面打开终端(terminal),输入

sudo vi /etc/hosts

然后提示输入系统密码
hosts文件就自动打开了
接着输入 i
进入编辑模式
将添加的网站,ip拷贝进去(在hosts文件末尾加上 199.232.68.133 raw.githubusercontent.com)
编辑完成之后,按esc,输入 : wq (冒号也要)

二次安装rvm,终端再次执行

curl -L get.rvm.io | bash -s stable
CJ@MacBook-Pro /etc % 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     21      0  0:00:09  0:00:09 --:--:--    40
100 24535  100 24535    0     0    365      0  0:01:07  0:01:07 --:--:--   316
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to api.github.com:443 
WARN: ...the preceeding error with code 35 occurred while fetching https://api.github.com/repos/rvm/rvm/tags
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc
Installing RVM to /Users/zhx/.rvm/
    Adding rvm PATH line to /Users/zhanghanxing/.profile /Users/zhanghanxing/.mkshrc /Users/zhanghanxing/.bashrc /Users/zhanghanxing/.zshrc.
    Adding rvm loading line to /Users/zhanghanxing/.profile /Users/zhanghanxing/.bash_profile /Users/zhanghanxing/.zlogin.
Installation of RVM in /Users/zhx/.rvm/ is almost complete:

  * To start using RVM you need to run `source /Users/zhanghanxing/.rvm/scripts/rvm`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
Thanks for installing RVM 
Please consider donating to our open collective to help us maintain RVM.

  Donate: https://opencollective.com/rvm/donate

看到拜佛没??那就成功了~~
按照提示,终端输入

source /Users/zhx/.rvm/scripts/rvm

3、查看rvm版本

rvm -v 

显示如下(也可能是其他版本)

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

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

rvm list known

显示如下

# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
.....
[ruby-]2.6[.2] 
[ruby-]2.7[.4] // 这里没有显示2.6.3,大大的问号脸...  
[ruby-]3.0[.0]   
ruby-head

5、安装一个ruby版本(开始安装2.6.3,提示没有这个版本,于是更换为最新的3.0.0)

rvm install 3.0.0

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

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

都会在下载进度在10%~20%之间中断,提示:

error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

也就是Homebrew安装失败,于是百度到的大部分结果为更改下载最大缓存和限制网速,做如下更改

git config --global http.postBuffer 524288000
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999

结果再次,坑2依旧存在,直到找到大神: 白壮丽 的博客参照3 安装Homebrew,终端输入:

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

按照提示又是1,又是Y的.又是password的,直到提示:==> 安装完成,brew版本.

6、设置为默认版本(等待时间有点微长...此处完事凌晨3点~~)

rvm use 3.0.0 --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

到此,尽情的使用pods吧~~

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