1.检查Rvm、Ruby HomeBrew 是否安装
1.1 检查Rvm
1.1.1检查rvm安装环境
rvm -v
存在的情况下
rvm 1.29.3 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
不存在的情况下
zsh: command not found: rvm
1.1.2 安装 rvm
curl -L get.rvm.io | bash -s stable
如果不行,可能是没设置公钥
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ curl -sSL https://get.rvm.io | bash -s stable
# 如果上面的连接失败,可以尝试:
$ curl -L https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable
更新环境
source ~/.bashrc
source ~/.bash_profile
source ~/.profile
检查Rvm是否安装成功
rvm -v
1.2 检查Homebrew
1.2.1 检查Homebrew 是否安装
brew -v
1.2.2安装Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
报错
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
解决1:
在浏览器中直接输入地址https://raw.githubusercontent.com/Homebrew/install/master/install.sh
如果也不能访问,则可通过修改hosts方式解决
具体步骤如下:
-
1.首先可以在https://www.ipaddress.com查看raw.githubcontent.com对应的IP地址
截屏2021-10-10 上午10.16.26.png -
2 前往文件夹/etc,找到hosts文件,复制一份到桌面(多复制一份,避免出问题时,还可以复原),再打开桌面上的hosts,在最后加上 185.199.108.133 raw.githubusercontent.com,再将桌面的hosts文件替换掉/etc中的hosts文件
截屏2021-10-10 上午11.34.34.png
解决2:
sudo gem install redis
报错:
fatal: unable to access 'https://github.com/Homebrew/brew' : LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to guthub.com 443
解决:
ping下github.com,如果ping不通,参考解决1,修改下hosts配置
1.3 检查Ruby
1.3.1 检查Ruby安装环境
ruby -v
1.3.2 安装Ruby
- 1 修改 RVM 下载 Ruby 的源,到 Ruby China 的镜像ruby-china.com:
echo "ruby_url=https://cache.ruby-china.com/pub/ruby" > ~/.rvm/user/db
- 2 列出 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.0]
- 3 选择一个Ruby版本安装
rvm install 2.7.0
- 4 设置 Ruby 版本
rvm use 2.7.0 --default
安装ruby并设置为系统默认版本
rvm install 2.7.0 --default
这个时候你可以测试是否正确
ruby -v
ruby 2.3.0 ...
gem -v
2.1.6
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
2.安装CocoaPods
2.1 查看CocoaPods版本
pod --version
2.2 安装CocoaPods
- 更换ruby镜像
// 查看镜像
gem sources -l
// 删除其他镜像,并将Ruby镜像设置为gems.ruby-china.com
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
// 或者
gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
- 安装cocoapods
$ sudo gem install -n /usr/local/bin cocoapods
或
$ /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
- 3.查看pods版本
pod --version
- 如果安装了多个Xcode使用下面的命令选择(一般需要选择最近的Xcode版本)
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
- setup
$ pod setup
此过程需漫长等待,打印详情如下:
Setting up CocoaPods master repo
$ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
Cloning into 'master'...
remote: Enumerating objects: 436, done.
remote: Counting objects: 100% (436/436), done.
remote: Compressing objects: 100% (319/319), done.
Receiving objects: 7% (195802/2636757), 39.11 MiB | 60.00 KiB/s
......
- 下载本地库
最新版的MacOS Catalina 及以后的系统命令行执行pod setup命令后直接结束啦;
莫着急,我们手动安装本地库,速度绝对快
命令行执行以下操作
git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
注意:
重要的事情要重申:
使用这个命令执行等待一段时间之后大有可能会失败,
原因基本是网络问题,
请不要着急,
根据自己和小伙伴的多次测试,
只有在使用移动手机网络或者在凌晨的时候网速才会理想
(大概几分钟就OK,其他情况下即使你的网络带宽很好也没用)
或者使用下面的,国内镜像,速度刚刚的
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
前往文件夹~/,看下cocoapods目录,cocoapods是隐藏文件,可以通过command+shift+. 查看
- 验证下pod 是否正常
pod search 'AFnetworking'
报错
[!] Unable to find a pod with name, author, summary, or description matching XXX
解决:
rm ~/Library/Caches/CocoaPods/search_index.json
如果还不行,那就有可能是没下载本地库,执行下上述步骤6
3.CocoaPods 使用
新建一个Xcode工程,使用终端cd到工程目录下
vim Podfile
在Podfile中加入需要pod的三方库
target 'XXXX' do
use_frameworks!
pod 'AFNetworking','3.2.0'
pod 'JSONModel', '~> 1.0.2'
pod 'Masonry', '1.1.0'
end
在命令行中,加载三方库
pod install
报错
fatal: unable to access 'https://github.com/cloudkite/Masonry.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
有可能是网络问题,多试几次
或者修改hosts,方法如上~