當前時間20200826
一撒桨、CocoaPods問題
好久沒動過iOS項目不瓶,電腦上cocoapods好像直接不能用了俺祠。執(zhí)行pod命令也是直接報各類錯誤,先記錄如下:
1.執(zhí)行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.根據網上搜索浑吟,執(zhí)行安裝命令也是報錯:
$ 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.執(zhí)行卸載cocoapods命令呢永票,則是提示沒有安裝(其實我記得有裝的)
$ sudo gem uninstall cocoapods
Gem 'cocoapods' is not installed
以上問題開始網上搜搜各種解決辦法無效昏滴,最后還是把rvm和ruby更新了一波昼窗,按順序詳見:
《Mac系統(tǒng)更新RVM到最新版本》
《Mac系統(tǒng)下ruby更新和配置》
二、安裝CocoaPods
更新完確認rvm和ruby環(huán)境正常之后敷燎,下面執(zhí)行CocoaPods的安裝操作:
- 查看當前的鏡像ruby源(正是當前時間點想要的)
$ gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.com
如果不是暂筝,執(zhí)行以下操作:
移除:$ gem sources --remove https://ruby.taobao.org
添加:$ gem sources -a https://gems.ruby-china.com
2.執(zhí)行安裝指令:
$ sudo gem install -n /usr/local/bin cocoa pods
$ pod setup
3.執(zhí)行結束之后查看當前版本,如果查到則安裝成功:
$ pod --version
1.9.3
另外可以查看cocoapods的安裝路徑:
$ which pod
/usr/local/bin/pod
4.如果想要刪除cocoapods硬贯,執(zhí)行:
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.在創(chuàng)建Podfile并且執(zhí)行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. 比較麻煩所以嘗試了下面兩種方式解決:
方式一:翻墻到外網,然后直接執(zhí)行語句墨状;實際是可行的卫漫,但是我用的免費的工具,網速賊慢 最后斷了....
方式二:如此看來就是網絡連不到嘛肾砂,然后參照替換host文件:
(1)打開網站: https://www.ipaddress.com/
(2)查詢一下 github.com 對應的IP地址
(3)進入 /etc 目錄下替換系統(tǒng)的 hosts 文件(直接修改是沒有權限的,復制出來修改后拷貝進去替換)
注意:最好備份一份
按照這個方式配置后終端輸入命令宏悦,發(fā)現(xiàn)可行镐确,只是速度也是極慢(最后機子開著過夜一早查看安裝成功,主要是第一次配置饼煞,他給配置安裝本地庫的耗時)