Mac下都自带ruby,但是如果gem版本太老,可能也会有问题。可以升级gem版本,但是因为ruby 的软件源( https://rubygems.org )使用的是亚马逊的云服务,自带的需要翻墙,所以我用的是淘宝的源https://ruby.taobao.org/。据说用Ruby China 社区专注维护的这个源https://gems.ruby-china.org/也可以。
替换Ruby
1.首先执行以下命令,删除原来的ruby源:
$ gem sources --remove https://rubygems.org/
2.替换成淘宝源。(网上说淘宝源有卡的可能,我用的时候没出现卡的现象,所以没有尝试用China社区的,淘宝卡的同学可以尝试用China 社区的源)
$ gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
$ gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org/
安装CocoaPods
执行sudo gem install 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
问题二
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/fuzzy_match
解决方案 :
执行sudo gem install -n /usr/local/bin cocoapods
语句。然后提示gems installed即可。
问题三
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/xcodeproj
解决方案:
sudo gem install -n /usr/local/bin cocoapods --pre
问题四
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解决方案:
sudo gem install -n /usr/local/bin cocoapods
问题五
Error installing pods:active support requires Ruby version >= 2.2.2
解决方案:
1.查看ruby版本,终端会输出你的ruby 版本信息
$ ruby -v
2.查看目前的所有ruby版本:
$ rvm list known
如果提示command not found 请先安装rvm
$curl -L get.rvm.io | bash -s stable
如果已安装会列出所有的ruby版本:
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.6]
[ruby-]2.3[.3]
[ruby-]2.4[.0]
ruby-head
下面还有一堆就不放了。。。太长了。。。
安装2.2.2: $ rvm install 2.2.2
安装顺利的话就一直下去了,但是有可能会出现以下报错
Requirements installation failed with status: 1
执行以下命令
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2017.12.13更新
问题: 新项目pod install
时报以下错误
MacBook-Pro:Demo wei$ pod install
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory
MacBook-Pro:Demo wei$ pod --version
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory
查资料之后说要更新ruby, 再重装cocoapods.
先后执行了 sudo gem update --system
和 sudo gem install cocoapods
更新ruby没哈, 重装cocoapods不得了...
MacBook-Pro:Demo wei$ sudo gem install cocoapods
Fetching: concurrent-ruby-1.0.5.gem (100%)
Successfully installed concurrent-ruby-1.0.5
Fetching: i18n-0.9.1.gem (100%)
Successfully installed i18n-0.9.1
Fetching: thread_safe-0.3.6.gem (100%)
Successfully installed thread_safe-0.3.6
Fetching: tzinfo-1.2.4.gem (100%)
Successfully installed tzinfo-1.2.4
Fetching: activesupport-4.2.10.gem (100%)
Successfully installed activesupport-4.2.10
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: fuzzy_match-2.0.4.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
没有/usr/bin的权限? !
再查资料, 说是可以修改权限, 又试了试
MacBook-Pro:Demo wei$ sudo chmod 777 /usr/bin
chmod: Unable to change file mode on /usr/bin: Operation not permitted
晋升到没有操作权限? !
再查, 说是Mac在升级为OS X EI Capitan之后, 增加了一个rootless机制, 该机制被称为最后一道防线, 增加了普通用户在使用过程中的安全性...
大神们提供了几个解决方案, 由于时间紧迫, 我采取的最快的一种:
修改路径, 其实就是/usr/bin的权限被禁了, 那就不在/usr/bin下创建, 换个地儿
MacBook-Pro:Demo wei$ sudo gem install -n /usr/local/bin cocoapods
MacBook-Pro:Demo wei$ pod --version
1.3.1
想了解其他解决方案的同学, 移步👇
参考路径: http://blog.csdn.net/yhf_szb/article/details/51809146
网友评论