背景
CocoaPodsをインストール、導入する時に発生する問題を解決するために導入手順を作成しました。
- ターミナルのアプリにフルディスクアクセスを許可
- CocoaPodsのインストール
- Homebrewのインストール
- Rubyの環境設定
- Rubyのバージョンアップ
- 再度CocoaPodsのインストール
- Podfileの作成
- Podfileの編集
- Xcodeプロジェクトにpodインストール
- Xcodeプロジェクトのクリーンビルド
- SwiftPackageManager
既存のプロジェクトで実行すると問題点が切り分けられなくなるため、Xcodeプロジェクトを新規作成して実行してください。
環境
- MacBook Pro 13-inch, M1, 2020
- macOS Sequoia 15.5
- XCode Version 16.4
macOSのバージョンでディスクアクセス権や
インストールされているRubyバージョンが変更されます。
ターミナルのアプリにフルディスクアクセスを許可
システム設定アプリ
[プライバシーとセキュリティ] -> [フルディスクアクセス] -> [ターミナル]
CocoaPodsのインストール
sudo gem install cocoapods
ERROR: Error installing cocoapods:
The last version of securerandom (>= 0.3) to support your Ruby & RubyGems was 0.3.2. Try installing it with `gem install securerandom -v 0.3.2` and then running the current command again
securerandom requires Ruby version >= 3.1.0. The current ruby version is 2.6.10.210.
Rubyのバージョンを3.1.0以上にする必要があります。
brewコマンドを実行できる様にHomebrewのインストールが必要です。
Homebrewのインストール
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Password:
==> The Xcode Command Line Tools will be installed.
Press RETURN/ENTER to continue or any other key to abort:
Password:
Warning: /opt/homebrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the 'Next steps' section below.
Rubyの環境設定
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)" \neval "$(rbenv init - zsh)"') >> ~/.zshrc
source ~/.zshrc
brew install rbenv ruby-build
Rubyのバージョンアップ
rbenv install -l
rbenv install 3.4.4
rbenv global 3.4.4
rbenv versions
system
* 3.4.4 (set by /Users/hoge/.rbenv/version)
ruby -v
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [arm64-darwin24]
再度Cocoapodsのインストール
sudo gem install cocoapods
...省略
Successfully installed cocoapods-1.16.2
34 gems installed
Podfileの作成
pod init
ディレクトリにPodfileが作成されたことを確認します。
Podfileの編集
platform :ios, '9.0'
target 'MyApp' do
# use_frameworks!
pod 'Alamofire'
end
targetにインストールするライブラリを記述します。
今回はAlamofireをインストールします。
Xcodeプロジェクトにpodインストール
pod install
[!] Please close any current Xcode sessions and use `MyApp.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
Xcodeプロジェクトのクリーンビルド
Podのインストールで作成された、.xcworkspaceをXCodeで開きます。
- メニューより [Product] -> [Clean Build Folder...]を選択します。
- メニューより [Product] -> [Build]を選択します。
SwiftPackageManager
Xcodeプロジェクトのライブラリ管理にはいくつかの選択肢がありますが、ライブラリがSwift Package Managerに対応している場合は、Swift Package Managerで構成することができます。
Xcodeメニューでプロジェクトにインストールします。
CocoaPodsの導入手順は不要になります。