本文意在解決因ruby版本太低導(dǎo)致pod無法更新repo的問題
挖的坑
因?yàn)楸救说恼`操作,將cocoapods本地的repo刪除了传蹈,為了恢復(fù)repo,將gem升級到了2.6.0
,又將cocoapods升級為1.4.0
,升級完成后執(zhí)行 pod setup
或pod repo update --verbose
后一直無法把github上的repo拉取到本地概荷,最后確定為ruby版本過低造成,mac系統(tǒng)自帶2.0.0
版本的ruby會導(dǎo)致新版的cocoapods運(yùn)行異常碌燕,因此在不影響系統(tǒng)原ruby的情況下新增一個(gè)2.3.0
版本的ruby用于cocoapods误证。
環(huán)境
-
mac
:macOS Sierra 10.12.6 -
ruby
:2.0.0 -
gem
:2.6.0 -
pod
:1.4.0
解決方法
1.卸載原來的cocoapods
按順序執(zhí)行如下命令:
1.1 刪除pod
sudo rm -rf echo $(which pod)
1.2 卸載cocoapods
sudo gem uninstall cocoapods
1.3 刪除cocoapods的相關(guān)包
sudo gem uninstall cocoapods-core
sudo gem uninstall cocoapods-downloader
sudo gem uninstall cocoapods-plugins
sudo gem uninstall cocoapods-search
sudo gem uninstall cocoapods-stats
sudo gem uninstall cocoapods-trunk
sudo gem uninstall cocoapods-try
2.安裝高版本的ruby(2.3.0)
安裝ruby有三種方法:
- rbenv
- rvm
- homebrew
rbenv和rvm安裝的方式可自行百度查看。
嘗試采用rvm安裝:rvm install 2.3.0
安裝失敗修壕,make.log日志如下:
Configured with: /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_gcc49/gcc49/work/gcc-4.9.4/configure --prefix=/opt/local --build=x86_64-apple-darwin16 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc49 --includedir=/opt/local/include/gcc49 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.9 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.9 --with-gxx-include-dir=/opt/local/include/gcc49/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --disable-isl-version-check --with-cloog=/opt/local --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-build-config=bootstrap-debug --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --disable-tls --with-pkgversion='MacPorts gcc49 4.9.4_2' --with-build-config=bootstrap-debug
Thread model: posix
gcc version 4.9.4 (MacPorts gcc49 4.9.4_2)
compiling main.c
compiling dmydln.c
compiling miniinit.c
compiling dmyext.c
compiling miniprelude.c
translating probes probes.d
compiling bignum.c
compiling class.c
compiling compar.c
error: error reading '/dev/fd/9'
1 error generated.
clang: error: unable to remove file: Operation not permitted
dtrace: failed to compile script probes.d: Preprocessor failed to process input program
make: *** [probes.h] Error 1
make: *** Waiting for unfinished jobs....
++ return 2
修改/dev/fd
的所有權(quán)以及讀寫權(quán)限愈捅,問題依舊沒有解決,如果有遇到過類似問題解決了的朋友還請不吝賜教慈鸠。
最后采用homebrew的方式安裝成功蓝谨,步驟如下。
2.1 安裝ruby@2.3.0
brew update
brew install ruby@2.3.0
2.2 添加2.3.0
的ruby至環(huán)境變量
系統(tǒng)自帶的ruby路徑:/usr/bin/ruby
新增的ruby路徑:/usr/local/opt/ruby@2.3/bin/ruby
注意不要改動(dòng)或刪除系統(tǒng)自帶的ruby以及其環(huán)境變量
執(zhí)行以下命令:
echo 'export PATH="/usr/local/opt/ruby@2.3/bin:$PATH"' >> ~/.bash_profile
檢查一下是否添加成功:
which ruby
若輸出/usr/local/opt/ruby@2.3/bin/ruby
說明添加成功青团。
查看一下目前ruby的版本:
ruby --version
若輸出ruby 2.3.7p456
說明新增的ruby安裝成功像棘。
2.3 更新gem
系統(tǒng)自帶的ruby自帶的gem路徑:/usr/bin/gem
新增的ruby自帶的gem路徑:/usr/local/opt/ruby@2.3/bin/gem
注意不要改動(dòng)或刪除系統(tǒng)自帶的ruby自帶的gem以及其環(huán)境變量
執(zhí)行以下命令:
gem update --system
查看update后的gem版本:
gem --version
若輸出2.7.7
說明update成功。
3.安裝新版本的cocoapods
經(jīng)過前兩步的鋪墊壶冒,把新版cocoapods的ruby環(huán)境以及gem準(zhǔn)備好,然后可以按照常規(guī)方法安裝新版的cocoapods了截歉。
sudo gem install -n /usr/local/bin cocoapods
然后setup一下胖腾,拉取github上的repo:
pod setup
有如下輸出說明setup成功:
Setting up CocoaPods master repo
$ /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
Cloning into 'master'...
remote: Counting objects: 2310001, done.
remote: Compressing objects: 100% (480/480), done.
remote: Total 2310001 (delta 253), reused 302 (delta 121), pack-reused 2309377
Receiving objects: 100% (2310001/2310001), 556.79 MiB | 618.00 KiB/s, done.
Resolving deltas: 100% (1330611/1330611), done.
Checking out files: 100% (254260/254260), done.
Setup completed
查看一下此時(shí)pod的版本:
pod --version
輸出1.5.3
至此,我們完成了ruby的新增以及新版cocoapods的安裝。
安利
下面安利一款homebrew的GUI工具Cakebrew咸作,圖形化界面管理homebrew的版本/倉庫以及formulae的install/update/uninstall
锨阿,專治各種終端恐懼癥←_←
步驟2.1
中的ruby@2.3.0也可以通過cakebrew來安裝:
最后不得不說一句,Homebrew大法好记罚,Cakebrew你值得擁有墅诡。