环境配置 首先 要注意ruby 版本 及gem 源问题
可以先下载shell 管理 工具homebrew、rwm等管理)
homebrew工具安装ruby流程https://www.jianshu.com/p/31b88efffaf9
//cocoapods 安装及自定 版本
$sudo gem install -n /usr/local/bin cocoapods (-v 1.6.1)
pod init 失败
[!] Oh no, an error occurred.
Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=%5BXcodeproj%5D+Unknown+object+version.&type=Issues
If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new
Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md
Don't forget to anonymize any private data!
尝试更新:
终端查看版本: $ pod --version
因为很多第三方会限制cocoapods的最低版本
比如Alamofire要求cocoapods版本为1.1以上
$ sudo rm -fr ~/.cocoapods/repos/master
$ pod setup
$ pod --version
安装:
温馨提示"$"是注释,拷贝"$"以后的命令就OK啦
1.查看ruby镜像最好更新到最新:
终端输入命令
$ ruby -v
完成输出:ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]
版本太低需要更新一下
2.安装更新
$ gem sources -l
设置新的源
$ (sudo)gem source -a https://gems.ruby-china.com
删除源
$ sudo gem sources -r https://rubygems.org
// $ sudo gem update cocoapods (弃用)
// $ sudo gem install cocoapods
原因:在stackoverflow搜到的解释是这样的,This is happening because Apple has enabled rootless on the new install,也就是说在10.11系统上苹果已经启用无根的安装。在这种情况下,如果你使用如下的命令:
$ sudo gem install -n /usr/local/bin cocoapods
Fetching: rubygems-update-2.6.8.gem (100%)
Successfully installed rubygems-update-2.6.8
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
kaiver520:pod kaiver$
输出:
Fetching: cocoapods-core-1.1.1.gem (100%)
Successfully installed cocoapods-core-1.1.1
3.换成清华大学master
成功之后不要急着执行pod setup,cocoapods这个项目比较大,从github上clone这个会很慢,这里直接使用国内的镜像作为master或者直接报错
$ pod setup
然后就是等啦(要很耐心的那种哦)
输出:
Setting up CocoaPods master repo
$ /usr/bin/git -C /Users/likangwei/.cocoapods/repos/master fetch origin
From https://github.com/CocoaPods/Specs
这时候不放心可以去目录下看看文件有没有变换
$ open ~/.cocoapods
在变就行了
输出:
Setup completed 恭喜终于搞好啦
pod install 如果报56或者54
默认缓存不够 加缓存 $git config http.postBuffer 524288000
remote: Enumerating objects: 362, done.
remote: Counting objects: 100% (362/362), done.
remote: Compressing objects: 100% (334/334), done.
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master`.
You can try adding it manually in `/Users/g/.cocoapods/repos` or via `pod repo add`.
git克隆失败 大致是源问题导致
如安装homebrew 安装卡主切换源即可
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
https://www.jianshu.com/p/e70b1bbb5ec4
error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Cloning into '/var/folders/sy/t4fx9p_567g6xdb7_prf_54h0000gn/T/d20220302-61090-en7uc4'...
fatal: unable to access 'https://github.com/matej/MBProgressHUD.git/': Failed to connect to github.com port 443: Operation timed out
Cloning into '/var/folders/3h/hh0t69t10slcb4wb5_gx8h6h0000gn/T/d20210415-976-wyjfgb'...
fatal: unable to access 'https://github.com/candyan/TencentOpenApiSDK.git/': Failed to connect to 127.0.0.1 port 1080: Connection refused
解决方案
在开启shadowsock的前提下,手动配置git的代理。git客户端输入如下两个命令就可以了。
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
http://也可以改成sockets5://,但是区别在于:socks5不支持通过pubkey免密登录github,每次提交代码只能输入用户名和密码。http可以支持免密登录。
取消代理:
git config --global --unset http.proxy
git config --global --unset https.proxy