CocoaPods安装方法

468 阅读1分钟

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

3.更新系统上的ruby

  • rvm list known列出可安装的版本,然后用install命令安装
  • rvm install 2.6.6这里我直接安装的是2.6.6版本

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已经安装完成!

8.检测功能是否正常

pod search AFNetworking来检查是否能正常使用
如果你是M1芯片的Mac,还需要做以下操作:

  • 访达-应用程序-实用工具里,右键点击终端-显示简介 (如果找不到实用工具,请以列表或分栏的方式显示项目)
  • 勾选使用Rosetta打开
  • 执行sudo gem install ffi

附:

  • Homebrew官方镜像地址 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • CocoaPods官方repo地址 git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/trunk