介绍
- 安装顺序:
Xcode->Homebrew->RVM->Ruby->CocoaPods
安装
Homebrew
Homebrew:是一个包管理器,用于在mac上安装一些os x上没有的UNiX工具(比如wget)- homebrew官方网站:brew.sh/index_zh-cn…
- mac 安装homebrew出错:Failed to connect to raw.githubusercontent.com port 443: Connection refused error:
原因:由于某些你懂的因素,导致GitHub的raw.githubusercontent.com域名解析被污染了。
解决办法:通过修改hosts解决此问题。
1、查询真实IP
在https://www.ipaddress.com/查询raw.githubusercontent.com的真实IP
2、修改hosts(4选1即可)
(1)sudo vim /etc/hosts
(2)hosts中添加如下内容:185.199.108.133 raw.githubusercontent.com
(3) /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
(4)/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
1、查看raw.githubusercontent.com的IP进行修改hosts
2. 开始安装
% /bin/bash -c "$(curl -fsSL raw.githubusercontent.com/Homebrew/in…)"
3. 成功后可以查看Homebrew版本
RVM
RVM:全称Ruby Version Manager,是一个非常好用的Ruby版本以及安装工具。就是用来安装和控制Ruby版本的工具。- 安装RVM: curl -L get.rvm.io | bash -s stable
- 载入RVM环境(新开 Termal 就不用这么做了,会自动重新载入的):
source ~/.rvm/scripts/rvm - 检查一下是否安装正确:
rvm -v - 列出已知的ruby版本 :
rvm list known - 查询已经安装的ruby :
rvm list - 卸载一个已安装版本 :
rvm remove 1.9.2
Ruby
Ruby:Ruby是一种面向对象的脚本语言,简单易用,功能强大。能跨平台和可移植性好等等,Ruby环境- 将指定版本的 Ruby设置为系统默认版本:
rvm install 2.7--default - 测试是否正确:
ruby -v - 查询版本:
gem -v - SSL verification error at depth 0: certificate has expired (10) 报错:是由于淘宝的tuby源不能用了,我们先删除原来的ruby源,然后更新为
gem sources -a <https://gems.ruby-china.com/> - 验证是否替换成功,执行:
gem sources -l
- 将指定版本的 Ruby设置为系统默认版本:
CocoaPods
- CocoaPods:
-
升级Ruby环境:
gem update --system -
如果没有权限去升级Ruby,就输入
sudo gem update --system -
换掉Ruby镜像:
gem sources --remove https://rubygems.org/ -
添加国内最新镜像源:
gem source -a https://gems.ruby-china.com/、gem sources --add https://gems.ruby-china.com/ --remove https://ruby.taobao.org/ -
安装CocoaPods:
sudo gem install cocoapods -
sudo gem install -n /usr/local/bin cocoapods -
pod --version :查看cocoapods版本
-
如果报下边的错
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.解决方案:
sudo gem install cocoapods -n /usr/local/bin
// 更强力的方式
sudo gem install cocoapods --user-install安装成功显示下边:
-
pod setup:将Github上的Pod托管的Podspec索引都安装到本地如果上述命令执行后什么都没做,则自己手动添加索引库
pod repo add master https://github.com/CocoaPods/Specs.git 如果出现该问题,克隆失败 Cloning spec repo `master` from `https://github.com/CocoaPods/Specs.git` [!] /usr/local/bin/git clone https://github.com/CocoaPods/Specs.git -- master \ 正克隆到 'master'... fatal: 无法访问 'https://github.com/CocoaPods/Specs.git/':LibreSSL SSL_connect: Operation timed out in connection to github.com:443- 方案一:该问题就说明网络不好,则再次执行上述命令
- 方案二:Cocoapods的GitHub下载zip,然后解压到
~/.cocoapods/repos/master目录下 备注:command + G,输入文件目录
-
查看索引是否配置成功:
% pod repo list% pod repo list cocoapods - Type: git (remotes/origin/master) - URL: https://github.com/CocoaPods/Specs.git - Path: /Users/aba/.cocoapods/repos/cocoapods master - Type: git (master) - URL: https://github.com/CocoaPods/Specs.git - Path: /Users/aba/.cocoapods/repos/master
-
- 在工程中创建一个Podfile文件
touch Podfile
- 编辑Podfile
vim Podfile
platform :ios, '10.0' target 'demo' do pod 'SDWebImage', end - pod install
坑点
1、在终端输入pod search 库名 可能会出现这种情况
这是因为之前pod search的时候生成了缓存文件search_index.json ,执行
-
rm ~/Library/Caches/CocoaPods/search_index.json
2、当运行pod 命令出现 command not found,执行:
-
sudo gem install -n /usr/local/bin cocoapods
3、如果pod update / pod install 卡在:Updating local specs repositories,原因可能x被墙,执行
-
pod install --verbose --no-repo-update
4、CocoaPods报错:CDN:trunk URL could't be downloaded:
CDN:trunk Repo update failed -128 error(s):-
CocoaPods 1.8将CDN切换为默认的
spec repo源 -
在Podfile中添加
source源 -
移除trunk源:
pod repo remove trunk
-
注意
install和update区别:install检索Podfile.lock文件,其中包含当时安装的三方库版本信息(锁定版本),update检索Podfile文件,如果未标注版本号的则自动下载最新,可能导致其他人下载时为最新三方库版本产生错误。specs:描述文件-->描述三方框架的信息,repo:本地索引库-->存放本地的specs文件。pod setup:从远程索引库更新本地索引库(pod需要升级的原因)创建specs描述文件:$pod spec create 文件名(最好跟原文件同名)上传spec文件到远程索引库:$git add .-->$git commit --m '描述'-->$pod trunk push 文件名-->删旧的检索文件-->$pod setup-->进行$pod search 文件名