macOS Monterey(MacOS 12) 系統(tǒng)升級(jí)cocoapods

老款MacBook系統(tǒng)Monterey(MacOS 12)由于brew停止了從上游下載cocoapods提示不支持os12系統(tǒng),無(wú)法安裝最新版cocoapods,本文講述了另一種方法來(lái)更新cocoapods

原文鏈接:http://www.kovli.com/2024/12/18/old-macos-install-cocoapods/

作者:Kovli

重要通知:紅寶書(shū)第5版2024年12月1日出爐了,感興趣的可以去看看,https://u.jd.com/saQw1vP

紅寶書(shū)第五版中文版

紅寶書(shū)第五版英文原版pdf下載(訪問(wèn)密碼: 9696)

嘗試過(guò)的方法:
sudo gem install cocoapods
sudo gem install cocoapods -pre
gem install cocoapods --user-install
sudo gem update cocoapods --version 1.16.2

均無(wú)法成功安裝,系統(tǒng)ruby是2.6

后來(lái)嘗試用brew安裝
brew install ruby

提示報(bào)錯(cuò)如下:

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.

經(jīng)過(guò)檢查是安裝了命令行工具14.2的,也重復(fù)安裝一遍還是報(bào)錯(cuò)同樣錯(cuò)誤,判斷是版本太低不支持,但是xCode14.2已經(jīng)是OS12系統(tǒng)的最新版本了,受限于系統(tǒng)無(wú)法升級(jí)。

于是想著升級(jí)下當(dāng)前系統(tǒng)所支持的最高ruby版本2.7.2
brew install ruby@2.7

報(bào)錯(cuò)如下,

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

報(bào)錯(cuò)如下

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?

也就是說(shuō)brew只支持安裝ruby3以上

于是安裝3.0版本試試
brew install ruby@3.0

結(jié)果報(bào)錯(cuò)如下

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

說(shuō)明brew已經(jīng)不支持macOS12系統(tǒng)安裝ruby3了,到這里可以看出,brew在macOS12系統(tǒng)已經(jīng)安裝不了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以上的,結(jié)果沒(méi)成功,經(jīng)過(guò)查詢,最高支持安裝2.7.2

rvm install 2.7.2

提示報(bào)錯(cuò)

Error running '__rvm_make -j8',

經(jīng)檢查問(wèn)題出在openssl
卸載openssl

brew uninstall --ignore-dependencies openssl@3

重裝低版本

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

提示報(bào)錯(cuò)

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

此時(shí)有種換電腦的沖動(dòng)了,但是不想讓老外的計(jì)謀得逞,繼續(xù)努力兼容!

brew edit openssl@1.1

會(huì)提示編輯如下文件

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

通過(guò)編輯器或者vim編輯,注釋下面這行

  deprecate! date: "2023-11-11", because: :unsupported
  # deprecate! date: "2023-11-11", because: :unsupported
然后執(zhí)行:
HOMEBREW_NO_INSTALL_FROM_API=1 brew install openssl@1.1
HOMEBREW_NO_INSTALL_FROM_API=1 這個(gè)環(huán)境變量的作用就是告訴brew 不使用api中的formula而是使用你自己編輯后的, 這樣就可以正常安裝被brew禁止disable的軟件包了。

上面的執(zhí)行完再次安裝2.7.2就可以成功

rvm install 2.7.2

設(shè)為默認(rèn)ruby

rvm use 2.7.2 --default

更新了ruby從系統(tǒng)默認(rèn)的2.6到rvm安裝的2.7.2后再次嘗試安裝cocoapods

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

提示報(bào)錯(cuò)

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.

按照指引繼續(xù)安裝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

提示報(bào)錯(cuò)

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.

按照指引開(kāi)始安裝activesupport

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

繼續(xù)重試

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

這次終于沒(méi)報(bào)錯(cuò)了,安裝成功,檢查版本

~ pod --version
1.16.2

成功更新到新版cocoapods

tips:

1、RVM官方網(wǎng)站
https://rvm.io/workflow/examples#rvm-list

2、ruby可安裝的版本信息

rvm list known

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

4、cocoapods官網(wǎng)
https://guides.cocoapods.org/using/getting-started.html


版權(quán)聲明:

轉(zhuǎn)載時(shí)請(qǐng)注明作者Kovli以及本文地址:
http://www.kovli.com/2024/12/18/old-macos-install-cocoapods/


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容