最新更新:使用软件包管理工具-brew,可以直接安装cocoapods。方法:brew install cocoapods 亲测有效
brew的安装可以参考我之前的一篇文章,这是---传送门
首先,先来说一下一般的方法吧,就是把之前的淘宝源替换成一个可用的的源:
使用终端查看当前的源
gem sources -l
gem sources -r https://rubygems.org/ #删除源
gem sources -a https://gems.ruby-china.org/ #添加源
我这里有一个比较好的一个源
https://gems.ruby-china.org/
之后使用sudu gem install cocoapods 然后输入管理员密码 就可以了
但是这样有个缺点,就是下载巨慢~~有些时候网络不稳定的话还会断掉。可能运气好的人一天可以安装上,但如果你是非洲人的话。嘿嘿嘿。
这个时候,忍不住想快一点的同学就可以看过来了。
首先,我们打开终端。cd 到这个路径
cd ~/.cocoapods/repos
当然如果没有的话就自己创建一个。也可以 gem install cocoapods,当看到出现cocoapods的目录时就可以终止了。
后面,我们cd到repos文件路径没问题了之后,重点来了。
- 方法一:
git clone https://github.com/CocoaPods/Specs
输入这个命令将cocoapods的索引文件下载下来
- 方法二:
浏览器打开:https://github.com/CocoaPods/Specs
使用ZIP下载的方式下载下来文件,解压到repos目录
- 方法三:
如果你有同事的话,找他拷贝一份~/.cocoapods/repos目录下的文件(这种方法最轻松!!)
好了,至此我们的索引文件夹就已经下载下来了,这也是网上遇到问题最多的,很费时,断网了还需要重头下载。。
最关键的一步来了。我们下载的这份名为Specs的文件夹需要改名为master,并且需要注意的是,它必须是在放在~/.cocoapods/repos这个路径下面的。如果不对请放好了再来。
之后 只需要cd ~/.cocoapods/repos/master路径,执行一步
git init
将git初始化一下,完成!至此你的电脑上已经能够正常使用cocoapods了。
网友评论
pod update提示错误:
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master-1`.
You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.
pod setup提示错误:
[!] CocoaPods was not able to update the `master` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
pod search提示错误:
[!] Unable to find a pod with name, author, summary, or description matching `AFN`
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/CocoaPods/Specs.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
输入pod setup命令,一直卡在这个地方:
Setting up CocoaPods master repo
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
$ /usr/bin/git -C /Users/fzq/.cocoapods/repos/master fetch origin