好记性不如烂笔头 每次换新电脑配置开发环境会容易坑一下
安装cocoapods报错
ERROR: Error installing cocoapods:
invalid gem: package is corrupt, exception while verifying: undefined method `size’ for nil:NilClass (NoMethodError) in /Library/Ruby/Gems/2.6.0/cache/rexml-3.2.6.gem
ruby环境不匹配
解决方案:
安装Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
官网地址:https://brew.sh/zh-cn/
测试验证homebrew
可选
brew install wget
报错了
==> Pouring portable-ruby-3.1.4.arm64_big_sur.bottle.tar.gz
Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the ‘Next steps’ section below.
解决方案:
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
然后再使用brew install wget 或者 brew list就可以正常使用了
安装ruby
brew install ruby (不确定ruby版本的可以用brew安装
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.3.1
看到版本号,下面安装使用)
ruby -v
最后安装 cocoapods
sudo gem install cocoapods
(如果碰上了这个错误:
ERROR: Error installing cocoapods:
invalid gem: package is corrupt, exception while verifying: undefined method `size' for nil:NilClass (NoMethodError) in /Library/Ruby/Gems/2.6.0/cache/rexml-3.2.6.gem
不要着急,打开“in”后面给出的路径,将最后一级目录里面的缓存文件删除,然后重新安装cocoapods即可。)
如果报错:
The last version of drb (>= 0) to support your Ruby & RubyGems was 2.0.6. Try installing it with `gem install drb -v 2.0.6` and then running the current command again drb requires Ruby version >= 2.7.0. The current ruby vers
终端输入
open ~/.zshrc //使用文本编辑器
//添加path配置
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/opt/homebrew/Cellar/ruby/3.3.1/bin:$PATH"
重启终端
使用 ruby -v
看到
ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
最新ruby了
可选: 更新安装源
更新gem
执行下面的命令更新gem
sudo gem update --system
替换安装源
将官方的ruby源替换成国内源
// 删除当前源
gem sources --remove https://rubygems.org/
// 切换当前源
gem sources -a https://gems.ruby-china.com/
// 列出当前使用的源
gem sources -l
最后进行安装 cocoapods
sudo gem install -n /usr/local/bin cocoapods
成功