这篇文章是转载的(转载自:https://www.jianshu.com/p/5d58a42a72d6),接手到一个ios的项目,原项目使用cocoapods管理的第三方库,但是我的新电脑上没有cocoapods环境,安装时碰到挺多问题的,这篇文章给我很大的帮助,以此记录一下。
在安装cocoapods上经历过不少折腾,终于实现了较为流畅的安装过程,在此做个记录,以便不时之需。
首先打开终端
1.安装Homebrew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
2.安装rvm
curl -L get.rvm.io | bash -s stable
source ~/.bashrc
source ~/.bash_profile
注:如果安装失败,可能需要修改hosts文件(在访达中commond+shift+G快速打开文件夹/private/etc,将hosts文件复制出来,修改后再替换回去即可),在文件中添加下面的链接,重新安装rvm
52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
151.101.76.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com
3.更新系统上的ruby
rvm install 2.6.3
这里我直接安装的是2.6.3版本,如果你想安装其他版本,也可先使用
rvm list known
列出可安装的版本,然后用install命令安装
注:如果安装ruby失败,可能需要修改hosts文件(方法上面有),在host文件中添加下面的链接,再重新安装
151.101.185.194 github.global.ssl.fastly.net
192.30.253.112 github.com
151.101.184.133 assets-cdn.github.com
151.101.184.133 avatars0.githubusercontent.com
151.101.112.133 avatars1.githubusercontent.com
4.将刚刚安装的ruby设置为默认版本
rvm use 2.6.3 --default
5.更换ruby镜像源
sudo gem update --system
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
可以使用
gem sources -l
来看是否更换成功
6.安装CocoaPods
sudo gem install -n /usr/local/bin cocoapods
7.clone CocoaPods仓库
这里使用的是清华大学fork的CocoaPods仓库
git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git ~/.cocoapods/repos/trunk
也可以用gitee上的一个私人fork的仓库,这个仓库比清华的速度更快,但是有可能更新不及时
git clone https://gitee.com/mirrors/CocoaPods-Specs.git ~/.cocoapods/repos/trunk
上面两个CocoaPods仓库选择一个clone就行了
到这里CocoaPods已经安装完成了,可以使用
pod search AFNetworking
来检查是否能正常使用
至此,cocoapods安装已经完成
在打开xcode项目后,如果pod文件无法解析,例如:error: unable to parse contents of file list '/xxx/Pods/Target Support Files/Pods-xxx/Pods-xxx-frame,需要在Podfile文件目录下执行pod install 或者pod update
*如果你是M1芯片的Mac,还需要做以下操作:
1.访达-应用程序-实用工具里,右键点击终端-显示简介 (如果找不到实用工具,请以列表或分栏的方式显示项目)
2.勾选使用Rosetta打开
3.执行sudo gem install ffi
附:
1.Homebrew官方镜像地址/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.CocoaPods官方repo地址git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk