Mac Pro M2安裝使用Cocoapods
在新公司要做iOS開發,所以在新電腦上安裝Cocoapods
在升級gem,sudo gem update --system
,和安裝cocoapods
時都遇到如下的提示:
ERROR: While executing gem ... (Errno::EPERM)Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/gem
原因大概是:Apple已內置安裝了ruby,不能修改
參考:
- While executing gem … (Gem::FilePermissionError)
the reason why you are getting that error is because Apple doesn’t allow you to install gems directly into the version of Ruby that came preinstalled on your Mac
其中的一個解決辦法就是,可通過安裝ruby版本管理器來解決,如chruby
或者RVM
安裝chruby
參考Install Ruby 3.1 · macOS
brew install ruby-install chruby
安裝后按提示,在.zshrc
中寫入如下的內容:
source /opt/homebrew/opt/chruby/share/chruby/chruby.sh
source /opt/homebrew/opt/chruby/share/chruby/auto.sh
chruby ruby-3.2.2
注意chruby ruby-3.2.2
,這個地方的ruby版本,已你安裝的版本為準
然后安裝Ruby,如下的代碼安裝并使用最新的ruby
ruby-install --latest ruby
安裝之前看下當前系統的ruby的版本:
ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]
SwitchHosts
在安裝過程中,可能會提示raw.githubusercontent.com
網站的內容不能訪問,此時需要配置host,推薦安裝SwitchHosts
host配置如下:
185.199.110.133 raw.githubusercontent.com
或者參考:
- ineo6/hosts
配置一個遠程的,自動更新的host
然后可能需要重啟系統才生效。繼續執行ruby-install --latest ruby
chruby
參考:
- postmodern/chruby
使用chruby
命令列出可用的ruby
使用chruby 3.2.2
,選擇3.2.2
的版本
cocoapods
參考官方文檔:
- WHAT IS COCOAPODS
安裝cocoapods
sudo gem install cocoapods
cocoapods鏡像
原始源地址為https://github.com/CocoaPods/Specs.git
參考CocoaPods 鏡像使用幫助
$ cd ~/.cocoapods/repos
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
最后進入自己的工程,在自己工程的podFile第一行加上:
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
ruby鏡像
移除現有的Ruby鏡像
gem sources --remove https://rubygems.org/
添加清華的鏡像,參考Ruby Gems 鏡像使用幫助
# 添加鏡像源并移除默認源
gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/
# 列出已有源
gem sources -l
# 應該只有鏡像源一個
gem
gem相關,可參考:
- RubyGems
查看gem版本:
gem -v
遇到的問題
1.pod install
時提示HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
按網絡上的說法解決:
git config --global http.version HTTP/1.1
2.git clone
時的各種出錯
猜測是由于國內的網絡環境造成的,所以可以給git配置代理
查看git代理:
git config --global --get http.proxy
git config --global --get https.proxy
設置git代理:
git config --global http.proxy "http://127.0.0.1:7890"
git config --global https.proxy "https://127.0.0.1:7890"
取消設置:
git config --global --unset http.proxy
git config --global --unset https.proxy
其他
可參考:
- m1 silicon macos 安裝 cocoapods
- CocoaPods 常見問題