tsx81429 发表于 2025-3-23 02:13:04

macOS Monterey(MacOS 12) 体系升级cocoapods踩坑指南

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

原文链接:http://www.kovli.com/2024/12/18/old-macos-install-cocoapods/
作者:Kovli
重要通知:红宝书第5版2024年12月1日出炉了,感爱好的可以去看看,https://u.jd.com/8alDI4w

实验过的方法:

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
先实验安装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.
按照指引继续安装securerandom
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.
按照指引开始安装activesupport
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
版权声明:
转载时请注明作者Kovli以及本文地点:
http://www.kovli.com/2024/12/18/old-macos-install-cocoapods/

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: macOS Monterey(MacOS 12) 体系升级cocoapods踩坑指南