macOS Catalina(10.15.5)环境下安装和使用cocoapods(20200826)

当前时间20200826

一、CocoaPods问题

好久没动过iOS项目,电脑上cocoapods好像直接不能用了。执行pod命令也是直接报各类错误,先记录如下:

1.执行pod命令报错(指向ruby的问题):

-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory

2.根据网上搜索,执行安装命令也是报错:

$ sudo gem install -n /usr/local/bin cocoa pods

Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.
    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200822-1104-pxufqf.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/include/ruby.h
You might have to install separate package for the ruby development
environment, ruby-dev or ruby-devel for example.
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.13.1/gem_make.out

3.执行卸载cocoapods命令呢,则是提示没有安装(其实我记得有装的)

$ sudo gem uninstall cocoapods
Gem 'cocoapods' is not installed

以上问题开始网上搜搜各种解决办法无效,最后还是把rvm和ruby更新了一波,按顺序详见:
《Mac系统更新RVM到最新版本》
《Mac系统下ruby更新和配置》

二、安装CocoaPods

更新完确认rvm和ruby环境正常之后,下面执行CocoaPods的安装操作:

  1. 查看当前的镜像ruby源(正是当前时间点想要的)
$ gem sources -l
*** CURRENT SOURCES ***

https://gems.ruby-china.com

如果不是,执行以下操作:

移除:$ gem sources --remove https://ruby.taobao.org

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

2.执行安装指令:

$ sudo gem install -n /usr/local/bin cocoa pods

$ pod setup

3.执行结束之后查看当前版本,如果查到则安装成功:

$ pod --version
1.9.3

另外可以查看cocoapods的安装路径:

$ which pod
/usr/local/bin/pod

4.如果想要删除cocoapods,执行:

sudo rm -rf /usr/local/bin/pod

并通过查询找到cocoapods包的安装位置,进行逐个删除:

$ gem list

*** LOCAL GEMS ***

activesupport (4.2.11.3)
algoliasearch (1.27.3)
atomos (0.1.3)
benchmark (default: 0.1.0)
bigdecimal (default: 2.0.0)
bundler (default: 2.1.2)
bundler-unload (1.0.2)
CFPropertyList (3.0.2)
cgi (default: 0.1.0)
claide (1.0.3)
cocoapods (1.9.3)
cocoapods-core (1.9.3)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.4.0)
cocoapods-plugins (1.0.0)
cocoapods-search (1.0.0)
cocoapods-stats (1.1.0)
cocoapods-trunk (1.5.0)
cocoapods-try (1.2.0)
colored2 (3.1.2)
...

三、CocoaPods使用问题处理

1.在创建Podfile并且执行pod语句的时候同样报错:

$ pod update
Update all pods
Updating local specs repositories
[!] Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down

查看网上的解决方案,大多说是 “2018年2月后,弱密码标准被删除” 总结起来一句话:update openssl, then ruby, then cocoapod. 比较麻烦所以尝试了下面两种方式解决:

方式一:翻墙到外网,然后直接执行语句;实际是可行的,但是我用的免费的工具,网速贼慢 最后断了....

方式二:如此看来就是网络连不到嘛,然后参照替换host文件:

(1)打开网站: https://www.ipaddress.com/
(2)查询一下 github.com 对应的IP地址
(3)进入 /etc 目录下替换系统的 hosts 文件(直接修改是没有权限的,复制出来修改后拷贝进去替换)
注意:最好备份一份

按照这个方式配置后终端输入命令,发现可行,只是速度也是极慢(最后机子开着过夜一早查看安装成功,主要是第一次配置,他给配置安装本地库的耗时)

你可能感兴趣的:(macOS Catalina(10.15.5)环境下安装和使用cocoapods(20200826))