美文网首页
Cocoapods 安装

Cocoapods 安装

作者: 张_何 | 来源:发表于2023-12-19 10:43 被阅读0次
说明
  • 作为iOS开发者,拿到一台新电脑通常需要先安装Cocoapods,下面记录一下安装Cocoapods步骤
  • 通常我们首先使用 ruby -v 指令来查看一下当前 ruby的版本
$ ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.x86_64-darwin23]
  • 其他安装教程中经常会看到使用 rvm -v 指令来查看rvm的版本或其他, 这个rvm其实是ruby的一个管理工具,可以帮助我们查看 ruby的版本列表,安装指定的ruby版本等。这里我们不用rvm 去管理或安装ruby,因为新电脑上一般是没有安装rvm的。
  • 通常新电脑上自带的ruby版本会比较低,所有在安装cocoapods会有各种问题,比如下面的
ERROR:  Error installing cocoapods:
    The last version of drb (>= 0) to support your Ruby & RubyGems was 2.0.5. Try installing it with `gem install drb -v 2.0.5` and then running the current command again
    drb requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.

// 或者
ERROR:  Error installing cocoapods:
    The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.6. Try installing it with `gem install activesupport -v 6.1.7.6` and then running the current command again
    activesupport requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.

这时我们通常需要升级ruby版本来修复这个问题

安装 Homebrew
  • 这里我们介绍使用 Homebrew来升级ruby版本,
    • 首先安装Homebrew, 可以通过/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"命令来安装,也可参考macOS系统安装Homebrew
    • 安装好Homebrew后,需要重启终端或者根据提示运行 source /Users/***/.zprofile 否则国内地址无法生效
升级 ruby
  • 在安装完 Homebrew后,就可以使用brew install ruby 指令来安装最新版本的ruby了。
  • 安装完ruby后,使用ruby -v 查看ruby的版本,发现还是原来的版本, 这是因为我们这时用该指令看到的还是系统安装的ruby的版本,我们使用which ruby指令可以看到显示的还是系统的ruby /usr/bin/ruby
  • 这时我们需要使用echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/***/.zprofile将使用homebrew安装的最新版的ruby的环境变量设置到我们的.zprofile文件中,然后重启终端,使用ruby -v查看ruby的版本就是我们安装的最新版本了
替换 gem
  • 使用gem sources -l查看gem
  • 使用 gem sources --remove https://rubygems.org/ 删除ruby源
  • 添加国内的源gem sources --add https://gems.ruby-china.com/
  • 使用: gem sources -l 查看添加是否成功
安装 Cocoapods
  • 安装: sudo gem install -n/usr/local/bin cocoapods
  • 安装本地库: git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master
  • 查看pod 版本 : pod --version

以上就是Cocoapods安装的完整步骤

相关文章

网友评论

      本文标题:Cocoapods 安装

      本文链接:https://www.haomeiwen.com/subject/bchkgdtx.html