近日用新MacBook(M1)安裝了 cocoapods環境,一堆坑,整的我不要不要的,搞個通宵,寫個文章記錄一下!
安裝后的環境版本(小括號中 對應終端查看命令):
Homebrew 2.7.5 (brew -v)
Rvm: 1.29.12 (rvm -v)
Ruby: 2.6.3p62 (ruby -v)
Cocoapod: 1.10.1 (pod --version)>>>開始進入正題:
前菜:先查看Xcode下是否選中,不能空白:
一、檢查Homebrew環境:
查看命令:
brew -v
如果提示:zsh: command not found: brew 執行安裝命令:(來自Homebrew官網)
**/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"**
安裝homebrew報錯:curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to raw.githubusercontent.com:443
通過搜索引擎找了很多解決方案,有的說是DNS污染,需要配置host,通過域名反查IP后寫入hosts文件后,還是不能有效解決,最終采用國內鏡像源安裝。
yamol@YamoldeMacBook-Pro ~ % /bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
開始執行Brew自動安裝程序
[cunkai.wang@foxmail.com]
['2021-12-15 06:51:31']['12.1']
https://zhuanlan.zhihu.com/p/111014448
請選擇一個下載鏡像,例如中科大,輸入1回車。
源有時候不穩定,如果git克隆報錯重新運行腳本選擇源。cask非必須,有部分人需要。
1、中科大下載源 2、清華大學下載源 3、北京外國語大學下載源 4、騰訊下載源(不推薦) 5、阿里巴巴下載源(不推薦 缺少cask源)
請輸入序號: 1
你選擇了中國科學技術大學下載源
!!!此腳本將要刪除之前的brew(包括它下載的軟件),請自行備份。
->是否現在開始執行腳本(N/Y) y
--> 腳本開始執行
Mac os設置開機密碼方法:
(設置開機密碼:在左上角蘋果圖標->系統偏好設置->用戶與群組->更改密碼)
(如果提示This incident will be reported. 在用戶與群組中查看是否管理員)
==> 通過命令刪除之前的brew、創建一個新的Homebrew文件夾
請輸入開機密碼,輸入過程不顯示,輸入完后回車
Password:
開始執行
---備份要刪除的/usr/local/Homebrew到系統桌面....
---/usr/local/Homebrew 備份完成
-> 創建文件夾 /usr/local/Homebrew
運行代碼 ==> /usr/bin/sudo /bin/mkdir -p /usr/local/Homebrew
此步驟成功
運行代碼 ==> /usr/bin/sudo /bin/chmod -R a+rwx /usr/local/Homebrew
運行代碼 ==> /usr/bin/sudo /usr/sbin/chown yamol /usr/local/Homebrew
運行代碼 ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Homebrew
---備份要刪除的/Users/yamol/Library/Caches/Homebrew到系統桌面....
---/Users/yamol/Library/Caches/Homebrew 備份完成
git version 2.32.0 (Apple Git-132)
下載速度覺得慢可以ctrl+c或control+c重新運行腳本選擇下載源
==> 克隆Homebrew基本文件
未發現Git代理(屬于正常狀態)
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.
此步驟成功
--創建Brew所需要的目錄
運行代碼 ==> /usr/bin/sudo /usr/sbin/chown -R yamol:admin /usr/local/Homebrew
運行代碼 ==> /usr/bin/sudo /bin/mkdir -p /Users/yamol/Library/Caches/Homebrew
運行代碼 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/yamol/Library/Caches/Homebrew
運行代碼 ==> /usr/bin/sudo /usr/sbin/chown -R yamol /Users/yamol/Library/Caches/Homebrew
--依賴目錄腳本運行完成
==> 創建brew的替身
==> 克隆Homebrew Core
此處如果顯示Password表示需要再次輸入開機密碼,輸入完后回車
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)
開始下載后就不需要你操作,靜靜的等待安裝完就行了……
完成后執行 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.
下載完之后、根據路徑/Users/用戶名,找到rvm文件夾下,找到 /bin/rvm-installer中 rvm-installer雙擊,然后會出現下面的內容:
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
[進程已完成]
安裝完了rvm之后、還需要配置環境變量
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
查看當前版本
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 環境:
列出已知的ruby版本 : rvm list known
安裝一個版本 rvm install 2.6.3
** (可不看內容:**
①若出現問題,網上搜報錯容易解決
②查詢已經安裝的ruby** rvm list**
③卸載一個已安裝版本rvm remove 2.x.x
④RVM 裝好以后,需要執行下面的命令將指定版本的 Ruby 設置為系統默認版本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 ,執行下面的命令pod repo remove trunk如果不執行remove還可能會出現 CDN:trunk 的問題。 執行其他命令的過程中可能會生成trunk文件,和master同路徑目錄下。)
最后進入自己的工程,在自己工程的podFile第一行加上:
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
文章參考了:
CocoaPods 最新系統安裝 2021-01-28(包含M1)
感謝!