更新以前大家都是根据淘宝镜像来安装cocoapods,此篇文章也和大多数博文内容相仿。后来换电脑时,同事说淘宝镜像已经不能用了,网上又重新查看教程,确实都是这么说的!(好吧,我确实比较懒,都没有按照之前步骤去试一下)
1.有人说需要升级ruby
参考链接:爱敲代码的兔子---> iOS极速安装CocoaPods详细教程
gem update --system ===> ERROR
详细信息如下:
Fetching: rubygems-update-2.6.7.gem (100%)
Successfully installed rubygems-update-2.6.7
Parsing documentation for rubygems-update-2.6.7
Installing ri documentation for rubygems-update-2.6.7
Installing darkfish documentation for rubygems-update-2.6.7
Parsing documentation for rubygems-update-2.6.7
Installing RubyGems 2.6.7
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Library/Ruby/Site/2.0.0/rubygems/basic_specification.rb
或者 sudo gem update --system ===> ERROR
详细信息如下:
Fetching: rubygems-update-2.6.7.gem (100%)
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/update_rubygems
bobbobbob:~ apple$ sudo gem update --system
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/update_rubygems
解决上述Operation not permitted,使用sudo gem update -n /usr/local/bin --system
2.安装使用,gem install cocoapods
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
或者,sudo gem install cocoapods
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj
解决上述Operation not permitted,使用sudo gem install -n /usr/local/bin cocoapods ===> ERROR
参考链接:http://stackoverflow.com/questions/30812777/cannot-install-cocoa-pods-after-uninstalling-results-in-error/30851030#30851030
详细信息如下:
Successfully installed xcodeproj-1.4.2
Fetching: ruby-macho-0.2.6.gem (100%)
Successfully installed ruby-macho-0.2.6
Fetching: molinillo-0.5.7.gem (100%)
Successfully installed molinillo-0.5.7
Fetching: cocoapods-trunk-1.1.2.gem (100%)
Successfully installed cocoapods-trunk-1.1.2
Fetching: cocoapods-downloader-1.1.3.gem (100%)
Successfully installed cocoapods-downloader-1.1.3
Fetching: cocoapods-core-1.2.0.gem (100%)
Successfully installed cocoapods-core-1.2.0
Fetching: cocoapods-1.2.0.gem (100%)
ERROR: While executing gem ... (TypeError)
no implicit conversion of nil into String
解决上述no implicit conversion of nil into String,ruby需要升级,重复1的操作。
3.使用sudo gem install cocoapods --pre ===> ERROR
详细信息如下:
Fetching: colored2-3.1.2.gem (100%)
Successfully installed colored2-3.1.2
Fetching: cocoapods-core-1.2.1.beta.1.gem (100%)
Successfully installed cocoapods-core-1.2.1.beta.1
Fetching: cocoapods-1.2.1.beta.1.gem (100%)
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
4.如步骤2的错误,使用sudo gem install -n /usr/local/bin cocoapods --pre
详细信息如下:
……
……
21 gems installed
然后pod install --verbose --no-repo-update安装,若出现以下问题:
[!] You need at least git version 1.8.5 to use CocoaPods (Pod::Informative)
有一种可能是cocoapods安装成功了,但是链接Xcode的版本过低,所以需要更新Xcode。或者你电脑安装了多个版本的Xcode,就需要修改链接Xcode路径,改成链接电脑比较高版本的Xcode。
修改链接命令是:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
后面的路径根据你较高版本Xcode路径修改(只要把所需链接的xcode拖入终端就可以获取到了)。
安装步骤:
- 1.移除原ruby镜像源
gem sources --remove https://rubygems.org/
- 2.新增镜像源
gem sources -a https://gems.ruby-china.org/
- 3.查看你的Ruby镜像
gem sources -l
终端出现如下图所示,第三步成功
4.看来Ruby版本还可以,镜像安装成功。
小插曲:此时我以为cocoapods已安装,就使用 pod install ,详细信息如下:
/Library/Ruby/Site/2.0.0/rubygems.rb:254:in `bin_path': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/bin/pod:22:in `<main>'
5.如果之前安装过cocoapods,使用sudo gem uninstall cocoapods
6.安装cocoapods,使用gem install cocoapods
小插曲:此时我想cocoapods已安装,就使用 pod install ,详细信息如下:
[!] No `Podfile' found in the project directory.
原因:笨啊,没有Podfile文件啊。
7.如何使用将会在下一篇文章中详细介绍。
CocoaPod的使用