1. 替换Ruby源
将默认的 RubyGems 替换为ruby-china源
- 先检查源
sudo gem sources -l
结果
*** CURRENT SOURCES ***
https://rubygems.org/
- 移除旧源
sudo gem sources --remove https://rubygems.org/
- 添加ruby-china源
sudo gem sources -a http://gems.ruby-china.org/
- 再检查源,结果
*** CURRENT SOURCES ***
http://gems.ruby-china.org/
2. 更新gem
sudo gem update
3. 安装cocoapods
sudo gem install cocoapods
- 报错
ERROR: While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: cocoapods requires cocoapods-core (= 1.2.1), cocoapods-downloader (< 2.0, >= 1.1.3), cocoapods-trunk (< 2.0, >= 1.2.0), molinillo (~> 0.5.7), xcodeproj (< 2.0, >= 1.4.4), colored2 (~> 3.1), ruby-macho (~> 1.1)
- 换个方式更新gem
sudo gem update --system
- 重新执行安装
sudo gem install cocoapods
- 又特么报错(无文件操作权限)
ERROR:While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj
- 终极安装命令
sudo gem install -n /usr/local/bin cocoapods --pre
4. pod setup (慢)
使用国内镜像
pod repo remove master
pod repo add master [https://gitcafe.com/akuandev/Specs.git](https://gitcafe.com/akuandev/Specs.git)
git clone [https://git.coding.net/CocoaPods/Specs.git](https://git.coding.net/CocoaPods/Specs.git) ~/.cocoapods/repos/master
最后pod --version
、pod repo update
5. 在项目根目录创建Podfile(每次修改都要pod update)
image.png
记得在
platform :ios, '10.3'
加上iOS版本号,否则会报错
image.png
现在可以
pod update
、pod install
(pod update
时就包含了pod install
)
参考链接: