記錄更換電腦時(shí)安裝cocoapods遇到的問題
- 查看本地ruby源
$ gem source -l
提示如下:
*** CURRENT SOURCES ***
https://rubygems.org/
- 替換ruby源
先刪除老的源
$ gem source --remove https://rubygems.org/
提示如下:
https://rubygems.org/ removed from sources
3.添加新的國(guó)內(nèi)源
$ gem sources -a https://gems.ruby-china.com
4.安裝cocoapods
$ sudo gem install cocoapods
可能會(huì)報(bào)如下錯(cuò):
$ sudo gem install cocoapods
Building native extensions. This could take a while...
ERROR: Error installing sass:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.11.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20191022-2775-1q9uxye.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.11.1 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.11.1/gem_make.out
解決方法
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
執(zhí)行后會(huì)彈出安裝對(duì)話框,然后一路下一步就可以了。
- 再次執(zhí)行安裝命令
$ sudo gem install cocoapods
可能還會(huì)報(bào)錯(cuò):
Fetching: xcodeproj-1.15.0.gem (100%)
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
LukedeMacBook-Pro:~ luke$ sudo gem install -n /usr/local/bin cocoapods
解決辦法:
$ sudo gem install -n /usr/local/bin cocoapods
執(zhí)行安裝的目錄再次執(zhí)行即可斟珊, 看到如下提示即表示安裝成功:
Parsing documentation for cocoapods-1.9.1
Installing ri documentation for cocoapods-1.9.1
Done installing documentation for xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 6 seconds
6 gems installed
- 初始化pod,查看版本
$ pod setup
pod --version
到此Cocoapod就安裝完成了吞瞪。