# 如何处理 CocoaPods 常见问题？ (/zh-CN/reference/faq/integration/cocoapods_problems)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

一般的原因有：未安装 CocoaPods、安装 CocoaPods 时由于网络连接问题导致操作超时、本地 CocoaPods 仓库过时。

## pod: command not found [#pod-command-not-found]

**问题描述**

在终端进入项目根目录，运行 `pod init` 后，终端提示 `pod: command not found`。

**问题原因**

未安装 CocoaPods。

**解决方法**

参考如下步骤解决问题：

1. 在终端运行 `sudo gem install cocoapods`，输入管理员密码，安装 CocoaPods。
2. 成功安装后，重新进入项目根目录，运行 `pod init`，即可在项目文件夹下生成一个 `Podfile` 文本文件。

 :::warning[注意]
 如果运行 `sudo gem install cocoapods` 失败，请根据错误提示选择合适的解决方案：

  - 如果遇到网络问题，请查看 [443: Operation timed out](#443) 解决方案。
  - 如果遇到权限问题，例如 `You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory`，则建议运行 `sudo gem install -n /usr/bin cocoapods` 安装 CocoaPods。
 :::

<a id="443"></a>
## 443: Operation timed out [#443-operation-timed-out]

**问题描述**

安装 CocoaPods 失败，终端提示访问超时。错误信息示例如下：

```shell
fatal: unable to access 'https://github.com/Homebrew/homebrew-cask/': Failed to connect to github.com port 443: Operation timed out
```

**问题原因**

网络状况不好。

**解决方法**

参考如下步骤解决问题：

1. 参考如下链接，使用 Ruby Gems 镜像源：
   - https://mirror.tuna.tsinghua.edu.cn/help/rubygems/
   - [https://gems.ruby-china.com](https://gems.ruby-china.com/)

2. 在终端运行 `sudo gem install cocoapods`，重新安装 CocoaPods。

## 无法安装最新版 RTC SDK [#无法安装最新版-rtc-sdk]

**问题描述**

安装 RTC SDK 时遇到如下问题：

- 在 `Podfile` 文件中写入 `pod 'library_name'`，在终端运行 `pod install` 后，安装的 SDK 不是最新版。
- 在 `Podfile` 文件中写入 `pod 'library_name', 'latest_version'`，在终端运行 `pod install` 后，终端提示最新版不存在。错误信息示例如下：

```shell
[!] CocoaPods could not find compatible versions for pod "AgoraRtcEngine_iOS":
  In Podfile:
    AgoraRtcEngine_iOS (= 4.1.0)
None of your spec sources contain a spec satisfying the dependency: `AgoraRtcEngine_iOS (= 4.1.0)`.
```

**问题原因**

未更新本地的 CocoaPods 仓库。

**解决方法**

参考如下步骤解决问题：

1. 在终端运行 `pod repo update` 更新本地的 CocoaPods 仓库。
2. 重新运行 `pod install`，即可成功安装最新版 SDK。
