Cocoapods配置安装流程
2021-02-23 本文已影响0人
沐时
如果是新电脑,首选配置下环境
先安装 Xcode 开发工具,它将帮你安装好 Unix 环境需要的开发包
然后安装 Homebrew
顺序是Xcode,homebrew, rvm,ruby,cocoapods
安装CocoaPods需要Ruby环境,所以,首先要检查Ruby环境的版本!
1. 首先要检查Mac是否安装了rvm。打开终端,输入指令rvm -v

2.安装,终端 curl -L get.rvm.io | bash -s stable
***可能会提示Failed to connect to raw.githubusercontent.com port 443: Connection refused
大概率是某种网络环境的问题,查询真实IP
在https://www.ipaddress.com/查询raw.githubusercontent.com的真实IP。

修改hosts
sudo vim/etc/hosts
添加如下内容:
199.232.28.133raw.githubusercontent.com
或者直接使用switchhost配置也行
安装完,退出终端,再输入rvm -v (终端不退出,一直显示第一步那个状态)

3.列出所有指定源里的ruby版本 rvm list known

4.安装最新的 rvm install 2.4.0

安装的过程中如果之前没装过 homebrew会自动安装(不知道的可以自己研究下)
安装完会给提示

5.检查下安装的版本 rvm list

6.检查ruby源 gem sources -l

7.移除ruby源 gem sources --remove https://rubygems.org/

8.然后在添加 gem sources --add https://gems.ruby-china.com

9.在检查下

10.安装cocoapods , sudo gem install -n /usr/local/bin cocoapods(macOS10.11之后使用)
11.一般安装完,出现gems installed意味着你成功了,可是我出现了一个问题

再次使用pod,会执行很久的安装,安装时间看网速了

Question
1.

这个问题的解决参考:
1, pod repo remove master
2, cd ~/.cocoapods/repos
3, git clone --depth 1 https://mirrors.bfsu.edu.cn/git/CocoaPods/Specs.git master
4, rm ~/Library/Caches/CocoaPods/search_index.json
5, pod search afnetworking
上面的第三步之前使用的是
git clone --depth 1 https://github.com/CocoaPods/Specs.git master
根据上面的https://www.ipaddress.com/设置了github.com的代理也不行,修改了Spec源地址可以.
3.LoadError - cannot load such file -- openssl报错**
rvm安装ruby的时候,如果出现这个问题,需要指定路径
1.rvm pkg install openssl
2.rvm reinstall ruby-2.7.2 --with-openssl-dir=$rvm_path/usr
3.如果重新打开终端执行pod --version 会报-bash: pod: command not found ,这个时候需要切换系统默认ruby版本
3.1.rvm list 列出当前系统中的ruby版本
3.2.rvm use 2.2.6 --default 指定系统默认的ruby版本
这个问题第二次恶心我了,直接解决
rvm reinstall 2.7.2 --with-openssl-dir=/usr/local/Cellar/openssl/1.0.2q
4.使用RVM安装ruby过程中出现
Checking requirements for osx.
Installing requirements for osx.
Updating system.......
需要先运行下面命令,再安装:
rvm autolibs read-only
5.pod install卡顿失败
[!] Error installing LLSegmentViewController
[!] /usr/bin/git clone https://github.com/CoderLinLee/LLSegmentViewController.git /var/folders/s4/zxfnb2091y3021xvm_hj5r3r0000gn/T/d20210304-832-1lume7m --template= --single-branch --depth 1 --branch 1.1.13
Cloning into '/var/folders/s4/zxfnb2091y3021xvm_hj5r3r0000gn/T/d20210304-832-1lume7m'...
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
这个问题也不知道是网的原因还是执行
sudo gem install cocoapods
之后好的.
然后在pod install就可以了
我测了几遍,应该是网的原因,安装失败,多pod install几次,换个网试试.
文章参考链接:
1.http://www.jianshu.com/p/96f126ef67ce