Mac10.14安装cocoapods

记录更换电脑时安装cocoapods遇到的问题


  1. 查看本地ruby源

$ gem source -l
提示如下:
*** CURRENT SOURCES ***
https://rubygems.org/

  1. 替换ruby源

先删除老的源
$ gem source --remove https://rubygems.org/
提示如下:
https://rubygems.org/ removed from sources

3.添加新的国内源

$ gem sources -a https://gems.ruby-china.com

4.安装cocoapods

$ sudo gem install cocoapods

可能会报如下错:
$ 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

安装对话框

执行后会弹出安装对话框,然后一路下一步就可以了。

  1. 再次执行安装命令

$ sudo gem install cocoapods

可能还会报错:

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

执行安装的目录再次执行即可, 看到如下提示即表示安装成功:

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
  1. 初始化pod,查看版本

$ pod setup
pod --version

到此Cocoapod就安装完成了。

你可能感兴趣的:(Mac10.14安装cocoapods)