ERROR: Error installing cocoapods: invalid gem: package is corrupt, exception while verifying: und

好记性不如烂笔头 每次换新电脑配置开发环境会容易坑一下
安装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

在这里插入图片描述
成功

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值