黑蘋果(Hackintosh)上按教程安裝 CocoaPods 執行 `pod install` 卡住/報錯,Xcode 內無相關內容。
| 原因 | 表現 | 驗證方法 |
|---|---|---|
| 網絡封鎖 | `gem install cocoapods` 超時、`pod repo update` 卡住 | `curl -v https://rubygems.org` / `git clone https://github.com/CocoaPods/Specs.git` |
| Ruby 版本不匹配 | 系統 Ruby 過舊 (macOS 自帶 2.6.x),CocoaPods 需 ≥ 2.7 | `ruby -v`、`which ruby` |
| 權限問題 | `Permission denied @ dir_s_mkdir` | 未使用 `--user-install` 或 `sudo` |
| 鏡像源未配置 | 默認源在國外,極慢/連不上 | `gem sources -l` 檢查 |
gem sources --remove https://rubygems.org/
gem sources --add https://gems.ruby-china.com/
gem sources -l
# 輸出應僅含 ruby-china
gem install cocoapods --user-install
# 輸出提示路徑類似:/Users/xxx/.gem/ruby/3.0.0/bin
# 將該路徑加入 PATH
echo 'export PATH="$HOME/.gem/ruby/3.0.0/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
# 移除官方源
pod repo remove master
# 添加清華/阿里雲鏡像
pod repo add master https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git
# 或
pod repo add master https://mirrors.aliyun.com/git/CocoaPods/Specs.git
# 更新索引
pod repo update
# Podfile 頭部
source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
# source 'https://mirrors.aliyun.com/git/CocoaPods/Specs.git'
platform :ios, '13.0'
target 'MyApp' do
pod 'AFNetworking'
end
cd /path/to/project
pod install --verbose
# 成功輸出:Pod installation complete! There are X dependencies...
| 報錯 | 解決 |
|---|---|
| `Operation not permitted` | SIP 保護,用 `--user-install` 或禁用 SIP(不推薦) |
| `Failed to connect to GitHub` | 配置 git 代理:`git config --global https.proxy https://127.0.0.1:7890` |
| `incompatible Ruby version` | 用 rbenv/rvm 安裝 Ruby 3.0+:`rbenv install 3.2.2 && rbenv global 3.2.2` |
黑蘋果裝 CocoaPods 核心是**換源(RubyGems + Specs)+ 用戶級安裝 + 代理配置**。按上述步驟操作,99% 能解決「裝不上、卡住、Xcode 空白」問題。