Mac下 cocoapods 重装,及pod command 找不到解决

这里我就长话短说,直接上代码

1. 卸载已有的cocoapods

sudo gem uninstall cocoapods

2. 查看本地安装过的cocopods相关东西

gem list --local | grep cocoapods

3. 删除上述文件

sudo gem uninstall cocoapods-xxx

sudo gem uninstall cocoapods-core
sudo gem uninstall cocoapods-deintegrate
sudo gem uninstall cocoapods-downloader
sudo gem uninstall cocoapods-plugins
sudo gem uninstall cocoapods-search
sudo gem uninstall cocoapods-trunk
sudo gem uninstall cocoapods-try

4. 查看Ruby环境

gem sources -l

若不合适,即删除旧源 - 添加新源

gem source -r https://rubygems.org/
gem source -a https://ruby.taobao.org/ (已停用)
gem sources -a https://gems.ruby-china.com/ (用这个)

5. 安装cocoapods

sudo gem install cocoapods
或者 sudo gem install -n /usr/local/bin cocoapods --re

如果遇到
Unable to resolve dependencies: cocoapods requires cocoapods-core (= 0.35.0), claide (~> 0.7.0), xcodeproj (~> 0.20.2), cocoapods-downloader (~> 0.8.0)
则需要重新更新gem

sudo gem update --system

5.1 设置cocoapods

pod setup

所有的项目的 Podspec 文件都托管在 https://github.com/CocoaPods/Specs. 第一次执行 pod setup 时,CocoaPods 会将这些 podspec 索引文件更新到本地的 ~/.cocoapods/ 目录下,这个索引文件比较大.
为了更快的下载这些索引文件,我们更换 repo 源

这里我们用清华大学开源软件镜像站提供的源 https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git

$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/master
$ pod repo update
$ pod update  (切换到原 Podfile 文件所在的文件夹中)

如果需要更新索引文件, 最好按照上面的方式来做, 否则更新太慢. (如果报错, 那么需要把原来的 master 下的文件删掉)

如果遇到
[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down
我建议在 ~/.cocoapods/repos/master 的子目录 将Specs 文件名改为master,重新pod setup 等待一段时间,可能就会成功

6. 查看pod 版本

pod --version
1.3.1

7. 此时如果出现pod command找不到

将pod 添加到环境变量中 /usr/local/bin

具体操作可参考这篇文章

8. cocoapods 使用

1.进入到项目根目录下,生成Podefile文件

$pod init

2.填写对应的信息

3.下载第三方库

pod install

Podfile 基本格式

platform :ios, '9.0'

target '集成cocoapods' do
    pod 'AFNetworking'
    pod 'MJExtension'
end

参考

解决CocoaPods慢的小技巧
清华大学开源软件镜像站
清华大学开源软件镜像站 - CocoaPods 镜像使用帮助

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容