阅读

macOS Monterey(MacOS 12) 系统升级cocoapods

编者按: 红宝书第5版2024年12月1日出炉了,涵盖了JS最新版本ES15的特性,感兴趣的可以去看看,https://u.jd.com/saQw1vP 最近自己2015年的老朋友MacBookPro因为项目需求要升级cocoapods,花了不少时间,遇到很多坑,最终还是成功更新了cocoapods,记录下来,供大家参考。系统是Monterey(MacOS 12),官方已经不能再升级系统了

重要通知:红宝书第5版2024年12月1日出炉了,涵盖了JS最新版本ES15的特性,感兴趣的可以去看看,https://u.jd.com/saQw1vP

老款MacBook系统Monterey(MacOS 12)由于brew停止了从上游下载cocoapods提示不支持os12系统,无法安装最新版cocoapods,本文讲述了另一种方法来更新cocoapods

尝试过的方法:
sudo gem install cocoapods
sudo gem install cocoapods -pre
gem install cocoapods --user-install
sudo gem update cocoapods --version 1.16.2

均无法成功安装,系统ruby是2.6

后来尝试用brew安装
brew install ruby

提示报错如下:

Error: Your Command Line Tools are too outdated.
Update them from Software Update in System Preferences.

If that doesn't show you any updates, run:
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

Alternatively, manually download them from:
https://developer.apple.com/download/all/.
You should download the Command Line Tools for Xcode 14.2.

经过检查是安装了命令行工具14.2的,也重复安装一遍还是报错同样错误,判断是版本太低不支持,但是xCode14.2已经是OS12系统的最新版本了,受限于系统无法升级。

于是想着升级下当前系统所支持的最高ruby版本2.7.2
brew install ruby@2.7

报错如下,

Error: ruby@2.7 has been disabled because it is not supported upstream! It was disabled on 2024-06-15.

尝试brew安装ruby2.6
brew install ruby@2.6

报错如下

No available formula with the name "ruby@2.6". Did you mean ruby@2.7, ruby@3.2, ruby@3.1 or ruby@3.0?

也就是说brew只支持安装ruby3以上

于是安装3.0版本试试
brew install ruby@3.0

结果报错如下

Error: You are using macOS 12.
We (and Apple) do not provide support for this old version.

说明brew已经不支持macOS12系统安装ruby3了,到这里可以看出,brew在macOS12系统已经安装不了ruby了

于是考虑用rvm
curl -L get.rvm.io | bash -s stable

顺利安装了rvm最新版

rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

先尝试安装ruby 3以上的,结果没成功,经过查询,最高支持安装2.7.2

rvm install 2.7.2

提示报错

Error running '__rvm_make -j8',

经检查问题出在openssl
卸载openssl

brew uninstall --ignore-dependencies openssl@3

重装低版本

rm -rf /usr/local/etc/openssl@1.1

brew reinstall openssl@1.1

提示报错

Error: openssl@1.1 has been disabled because it is not supported upstream! It was disabled on 2024-10-24.

此时有种换电脑的冲动了,但是不想让老外的计谋得逞,继续努力兼容!

brew edit openssl@1.1

会提示编辑如下文件

Editing /usr/local/opt/openssl@1.1/.brew/openssl@1.1.rb

通过编辑器或者vim编辑,注释下面这行

deprecate! date: "2023-11-11", because: :unsupported

# deprecate! date: "2023-11-11", because: :unsupported
然后执行:
HOMEBREW_NO_INSTALL_FROM_API=1 brew install openssl@1.1
HOMEBREW_NO_INSTALL_FROM_API=1 这个环境变量的作用就是告诉brew 不使用api中的formula而是使用你自己编辑后的, 这样就可以正常安装被brew禁止disable的软件包了。

上面的执行完再次安装2.7.2就可以成功

rvm install 2.7.2

设为默认ruby

rvm use 2.7.2 --default

更新了ruby从系统默认的2.6到rvm安装的2.7.2后再次尝试安装cocoapods

sudo gem install cocoapods -v 1.16.2 -n /usr/local/bin

提示报错

ERROR:  Error installing cocoapods:
The last version of securerandom (>= 0.3) to support your Ruby & RubyGems was 0.3.2. Try installing it with `gem install securerandom -v 0.3.2` and then running the current command again
securerandom requires Ruby version >= 3.1.0. The current ruby version is 2.7.2.137.

按照指引继续安装

```
sudo gem install -n /usr/local/bin securerandom -v 0.3.2

然后重试

sudo gem install cocoapods -v 1.16.2 -n /usr/local/bin

提示报错

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

按照指引开始安装

```
sudo gem install -n /usr/local/bin activesupport -v 7.1.5.1

继续重试

sudo gem install -n /usr/local/bin cocoapods -v 1.16.2

这次终于没报错了,安装成功,检查版本

~ pod --version
1.16.2

成功更新到新版cocoapods

Tips:

1、RVM官方网站
https://rvm.io/workflow/examples#rvm-list

2、ruby可安装的版本信息
rvm list known

3、cocoapods所有版本
https://rubygems.org/gems/cocoapods/versions

4、cocoapods官网
https://guides.cocoapods.org/using/getting-started.html


鼓励一下

如果觉得我的文章对您有用,欢迎打赏(右边栏二维码),您的支持将鼓励我继续创作!”


咨询联系方式

  • 请发邮件: admin@kovli.com