(Xcode) 如何在 Mac M1/M2 上 安裝 Cocoapods
Published in
4 min readFeb 15, 2023
若在 M 系列晶片使用以下指令安裝會出錯
sudo gem install cocoapods
Error message
A new major version is available for Algolia! Please now use the https://rubygems.org/gems/algolia gem to get the latest features.
Successfully installed algoliasearch-1.27.5
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20230213-54503-1zh3t9.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h
You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-22/2.6.0/ffi-1.15.5/gem_make.out
在 Mac M1/M2 上安裝 HomeBrew
透過 HomeBrew 安裝 Cocoapods,輸入以下指令
brew install cocoapods
檢查是否安裝成功
pod --version
若出現以下錯誤
("xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun\n") (RuntimeError)
請使用以下指安裝缺少的套件
xcode-select --install
最後即可完成安裝 Cocoapods