1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CocoaPods 導入手順 【エラー発生の解決】

Last updated at Posted at 2025-06-20

背景

CocoaPodsをインストール、導入する時に発生する問題を解決するために導入手順を作成しました。

既存のプロジェクトで実行すると問題点が切り分けられなくなるため、Xcodeプロジェクトを新規作成して実行してください。

環境

  • MacBook Pro 13-inch, M1, 2020
  • macOS Sequoia 15.5
  • XCode Version 16.4

macOSのバージョンでディスクアクセス権や
インストールされているRubyバージョンが変更されます。

ターミナルのアプリにフルディスクアクセスを許可

システム設定アプリ
[プライバシーとセキュリティ] -> [フルディスクアクセス] -> [ターミナル]
プライバシーとセキュリティ.png
ターミナル.png

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:
Xcode Command Line Toolsのダウンロードするか問われますので、Enterキーでダウンロードします。
==> 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の環境設定

brewコマンドへのパスを通すため、.zshrcファイルに追加します。
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)" \neval "$(rbenv init - zsh)"') >> ~/.zshrc
~/.zshrcの設定を反映します。
source ~/.zshrc
rbenvのインストール
brew install rbenv ruby-build

Rubyのバージョンアップ

rbenvのインストールできるバージョンを確認します。
rbenv install -l
Rubyの安定バージョンで要求バージョン以上をインストールします。
rbenv install 3.4.4
グローバル設定を更新します。
rbenv global 3.4.4
設定が反映されていることを確認します。
rbenv versions
下記の様にバージョンが設定されていることを確認します。
  system
* 3.4.4 (set by /Users/hoge/.rbenv/version)
Rubyのバージョンを確認します。
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の作成

Xcodeプロジェクトのディレクトリに移動して実行します。
pod init

ディレクトリにPodfileが作成されたことを確認します。

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の導入手順は不要になります。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?