インストール方法
こちらの記事通りにCocoapodssのインストールを行います.
まず, 次のコマンドをターミナル上で実行します.
sudo gem install -n /usr/local/bin cocoapods
すると, 私の環境では以下のエラーメッセージが出力されました.
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.3.0/gems/ffi-1.12.2/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20200403-30301-1n8idnk.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.12.2 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.12.2/gem_make.out
このエラーの対処法を探るために「mkmf.rb can't find header files for ruby at」というキーワードで検索をかけました.
すると, こちらの記事を用いてエラーを解決できました.その手順を記します.
まず, AppleDeveloperよりCommand Line Tools (macOS 10.14)for Xcode 10.2.1をダウンロードします. このリンクよりAppleIDでログインをすることでダウンロードできます. ダウンロードが完了したらダウンロードファイルを実行しインストールを完了させてください.
次に, 以下のコマンドをターミナル上で実行します.
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
次に, 以下のコマンドをターミナル上で実行します.
sudo gem install -n /usr/local/bin cocoapods
そして, 最後にCocoppodsをセットアップして完了です.
pod setup
以上となります.
参考文献
[1]CocoaPodsを導入してみた
https://qiita.com/showylee/items/29220a8bd43fd76474d7
[2]MacOS(Mojave)でrailsをinstallしようとしてコケた
https://qiita.com/tzono/items/b80f6c343355a872dde6