CocoaPods在M1上安裝使用及出現(xiàn)的問題

近日用新MacBook(M1)安裝了 cocoapods環(huán)境,一堆坑,整的我不要不要的,搞個(gè)通宵,寫個(gè)文章記錄一下!

安裝后的環(huán)境版本(小括號(hào)中 對(duì)應(yīng)終端查看命令):

Homebrew 2.7.5 (brew -v)

Rvm: 1.29.12 (rvm -v)

Ruby: 2.6.3p62 (ruby -v)

Cocoapod: 1.10.1 (pod --version)>>>開始進(jìn)入正題:

前菜:先查看Xcode下是否選中,不能空白:

image

一、檢查Homebrew環(huán)境:

查看命令:

brew -v

如果提示:zsh: command not found: brew 執(zhí)行安裝命令:(來自Homebrew官網(wǎng))

**/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"**

安裝homebrew報(bào)錯(cuò):curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443

通過搜索引擎找了很多解決方案,有的說是DNS污染,需要配置host,通過域名反查IP后寫入hosts文件后,還是不能有效解決,最終采用國(guó)內(nèi)鏡像源安裝。

yamol@YamoldeMacBook-Pro ~ % /bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

              開始執(zhí)行Brew自動(dòng)安裝程序

              [cunkai.wang@foxmail.com]

          ['2021-12-15 06:51:31']['12.1']

        https://zhuanlan.zhihu.com/p/111014448

請(qǐng)選擇一個(gè)下載鏡像,例如中科大,輸入1回車。

源有時(shí)候不穩(wěn)定,如果git克隆報(bào)錯(cuò)重新運(yùn)行腳本選擇源。cask非必須,有部分人需要。

1、中科大下載源 2、清華大學(xué)下載源 3、北京外國(guó)語大學(xué)下載源  4、騰訊下載源(不推薦) 5、阿里巴巴下載源(不推薦 缺少cask源) 

請(qǐng)輸入序號(hào): 1

  你選擇了中國(guó)科學(xué)技術(shù)大學(xué)下載源

!!!此腳本將要?jiǎng)h除之前的brew(包括它下載的軟件),請(qǐng)自行備份。

->是否現(xiàn)在開始執(zhí)行腳本(N/Y) y

--> 腳本開始執(zhí)行

Mac os設(shè)置開機(jī)密碼方法:

  (設(shè)置開機(jī)密碼:在左上角蘋果圖標(biāo)->系統(tǒng)偏好設(shè)置->用戶與群組->更改密碼)

  (如果提示This incident will be reported. 在用戶與群組中查看是否管理員)

==> 通過命令刪除之前的brew、創(chuàng)建一個(gè)新的Homebrew文件夾

請(qǐng)輸入開機(jī)密碼,輸入過程不顯示,輸入完后回車

Password:

開始執(zhí)行

  ---備份要?jiǎng)h除的/usr/local/Homebrew到系統(tǒng)桌面....

  ---/usr/local/Homebrew 備份完成

-> 創(chuàng)建文件夾 /usr/local/Homebrew

運(yùn)行代碼 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew

此步驟成功

運(yùn)行代碼 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew

運(yùn)行代碼 ==> /usr/bin/sudo /usr/sbin/chown yamol /usr/local/Homebrew

運(yùn)行代碼 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew

  ---備份要?jiǎng)h除的/Users/yamol/Library/Caches/Homebrew到系統(tǒng)桌面....

  ---/Users/yamol/Library/Caches/Homebrew 備份完成

git version 2.32.0 (Apple Git-132)

下載速度覺得慢可以ctrl+c或control+c重新運(yùn)行腳本選擇下載源

==> 克隆Homebrew基本文件

未發(fā)現(xiàn)Git代理(屬于正常狀態(tài))

Cloning into '/usr/local/Homebrew'...

remote: Enumerating objects: 206378, done.

remote: Total 206378 (delta 0), reused 0 (delta 0)

Receiving objects: 100% (206378/206378), 54.24 MiB | 10.78 MiB/s, done.

Resolving deltas: 100% (153617/153617), done.

Updating files: 100% (2720/2720), done.

此步驟成功

--創(chuàng)建Brew所需要的目錄

運(yùn)行代碼 ==> /usr/bin/sudo /usr/sbin/chown -R yamol:admin /usr/local/Homebrew

運(yùn)行代碼 ==> /usr/bin/sudo /bin/mkdir -p /Users/yamol/Library/Caches/Homebrew

運(yùn)行代碼 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/yamol/Library/Caches/Homebrew

運(yùn)行代碼 ==> /usr/bin/sudo /usr/sbin/chown -R yamol /Users/yamol/Library/Caches/Homebrew

--依賴目錄腳本運(yùn)行完成

==> 創(chuàng)建brew的替身

==> 克隆Homebrew Core

此處如果顯示Password表示需要再次輸入開機(jī)密碼,輸入完后回車

Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...

remote: Enumerating objects: 1110596, done.

remote: Total 1110596 (delta 0), reused 0 (delta 0)

Receiving objects: 100% (1110596/1110596), 458.14 MiB | 10.75 MiB/s, done.

Resolving deltas:  59% (458306/772573)

開始下載后就不需要你操作,靜靜的等待安裝完就行了……

完成后執(zhí)行 brew -v 提示如下代表安裝成功:

Homebrew 2.7.5 Homebrew/homebrew-core (git revision 18218; last commit 2021-01-28)12

二、安裝RVM:

查看命令:

rvm -v

如果提示:zsh: command not found: rvm

下載安裝:

Holothurian-iMac ~ % git clone https://github.com/rvm/rvm.git

Cloning into 'rvm'...

remote: Enumerating objects: 92, done.

remote: Counting objects: 100% (92/92), done.

remote: Compressing objects: 100% (62/62), done.

remote: Total 59450 (delta 57), reused 53 (delta 29), pack-reused 59358

Receiving objects: 100% (59450/59450), 20.07 MiB | 30.00 KiB/s, done.

Resolving deltas: 100% (38714/38714), done.

下載完之后、根據(jù)路徑/Users/用戶名,找到rvm文件夾下,找到 /bin/rvm-installer中 rvm-installer雙擊,然后會(huì)出現(xiàn)下面的內(nèi)容:

Last login: Fri Aug 7 15:42:51 on ttys001

/Users/holothurian/rvm/binscripts/rvm-installer ; exit;

Holothurian-iMac ~ % /Users/holothurian/rvm/binscripts/rvm-installer ; exit;

Downloading https://github.com/rvm/rvm/archive/master.tar.gz

curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54

Could not download 'https://github.com/rvm/rvm/archive/master.tar.gz'.

  curl returned status '56'.

Downloading https://bitbucket.org/mpapis/rvm/get/master.tar.gz

Installing RVM to /Users/holothurian/.rvm/

    Adding rvm PATH line to /Users/holothurian/.profile /Users/holothurian/.mkshrc /Users/holothurian/.bashrc /Users/holothurian/.zshrc.

    Adding rvm loading line to /Users/holothurian/.profile /Users/holothurian/.bash_profile /Users/holothurian/.zlogin.

Installation of RVM in /Users/holothurian/.rvm/ is almost complete:

  * To start using RVM you need to run `source /Users/holothurian/.rvm/scripts/rvm`

    in all your open shell windows, in rare cases you need to reopen all shell windows.

Thanks for installing RVM ??

Please consider donating to our open collective to help us maintain RVM.

??  Donate: https://opencollective.com/rvm/donate

[進(jìn)程已完成]

安裝完了rvm之后、還需要配置環(huán)境變量

Holothurian-iMac ~ % vi ~/.bash_profile

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

Holothurian-iMac ~ % source ~/.rvm/scripts/rvm

查看當(dāng)前版本

Holothurian-iMac ~ % rvm -v

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

Holothurian-iMac ~ %

三、保證 ruby 版本要 > 2.2.2

用 RVM 安裝 Ruby 環(huán)境:

列出已知的ruby版本 : rvm list known

安裝一個(gè)版本 rvm install 2.6.3

** (可不看內(nèi)容:**

若出現(xiàn)問題,網(wǎng)上搜報(bào)錯(cuò)容易解決

查詢已經(jīng)安裝的ruby** rvm list**

卸載一個(gè)已安裝版本rvm remove 2.x.x

RVM 裝好以后,需要執(zhí)行下面的命令將指定版本的 Ruby 設(shè)置為系統(tǒng)默認(rèn)版本rvm 2.6.3 --default

)

四、更換鏡像源

sudo gem update --system

gem sources --remove https://rubygems.org/

gem sources --add https://gems.ruby-china.com/

查看 gem sources -l 提示成功:

*** CURRENT SOURCES ***

https://gems.ruby-china.com/

五、安裝CocoaPods:

新版的 CocoaPods 不允許用pod repo add直接添加master庫了,但是依然可以:

cd ~/.cocoapods/repos

$ pod repo remove master

$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master

(完事之后記得remove trunk ,執(zhí)行下面的命令pod repo remove trunk如果不執(zhí)行remove還可能會(huì)出現(xiàn) CDN:trunk 的問題。 執(zhí)行其他命令的過程中可能會(huì)生成trunk文件,和master同路徑目錄下。)

最后進(jìn)入自己的工程,在自己工程的podFile第一行加上:

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

文章參考了:

CocoaPods 最新系統(tǒng)安裝 2021-01-28(包含M1)

MacOS 安裝homebrew報(bào)錯(cuò)

zsh: command not found: rvm問題

感謝!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容