本文意在解决因ruby版本太低导致pod无法更新repo的问题
因为本人的误操作,将cocoapods本地的repo删除了,为了恢复repo,将gem升级到了
2.6.0,又将cocoapods升级为1.4.0,升级完成后执行pod setup或pod repo update --verbose后一直无法把github上的repo拉取到本地,最后确定为 ruby版本过低 造成,mac系统自带2.0.0版本的ruby会导致新版的cocoapods运行异常,因此在不影响系统原ruby的情况下新增一个2.3.0版本的ruby用于cocoapods。mac:macOS Sierra 10.12.6ruby:2.0.0gem:2.6.0pod:1.4.01.卸载原来的cocoapods
按顺序执行如下命令:
1.1 删除pod
sudo rm -rf echo $(which pod)1.2 卸载cocoapods
sudo gem uninstall cocoapods1.3 删除cocoapods的相关包
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-try2.安装高版本的ruby(2.3.0)
安装ruby有三种方法:
rbenv 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的所有权以及读写权限,问题依旧没有解决,如果有遇到过类似问题解决了的朋友还请不吝赐教。最后采用homebrew的方式安装成功,步骤如下。
2.1 安装
ruby@2.3.0brew update brew install ruby@2.3.02.2 添加
2.3.0的ruby至环境变量系统自带的ruby路径:
/usr/bin/ruby新增的ruby路径:
/usr/local/opt/ruby@2.3/bin/ruby注意不要改动或删除系统自带的ruby以及其环境变量
执行以下命令:
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
系统自带的ruby自带的gem路径:
/usr/bin/gem新增的ruby自带的gem路径:
/usr/local/opt/ruby@2.3/bin/gem注意不要改动或删除系统自带的ruby自带的gem以及其环境变量
执行以下命令:
gem update --system查看update后的gem版本:
gem --version若输出
2.7.7说明update成功。3.安装新版本的cocoapods
经过前两步的铺垫,把新版cocoapods的ruby环境以及gem准备好,然后可以按照常规方法安装新版的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查看一下此时pod的版本:
pod --version输出
1.5.3至此,我们完成了ruby的新增以及新版cocoapods的安装。
下面安利一款homebrew的GUI工具Cakebrew,图形化界面管理homebrew的版本/仓库以及formulae的
install/update/uninstall,专治各种终端恐惧症←_←