pod setup失败解决方法

本文意在解决因ruby版本太低导致pod无法更新repo的问题

挖的坑

因为本人的误操作,将cocoapods本地的repo删除了,为了恢复repo,将gem升级到了2.6.0,又将cocoapods升级为1.4.0,升级完成后执行 pod setuppod repo update --verbose后一直无法把github上的repo拉取到本地,最后确定为ruby版本过低造成,mac系统自带2.0.0版本的ruby会导致新版的cocoapods运行异常,因此在不影响系统原ruby的情况下新增一个2.3.0版本的ruby用于cocoapods。

环境

  • mac:macOS Sierra 10.12.6
  • ruby:2.0.0
  • gem:2.6.0
  • pod:1.4.0

解决方法

1.卸载原来的cocoapods

按顺序执行如下命令:

1.1 删除pod

sudo rm -rf echo $(which pod)

1.2 卸载cocoapods

sudo gem uninstall cocoapods

1.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-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的所有权以及读写权限,问题依旧没有解决,如果有遇到过类似问题解决了的朋友还请不吝赐教。

最后采用homebrew的方式安装成功,步骤如下。

2.1 安装[email protected]

brew update
brew install [email protected]

2.2 添加2.3.0的ruby至环境变量

系统自带的ruby路径:/usr/bin/ruby

新增的ruby路径:/usr/local/opt/[email protected]/bin/ruby

注意不要改动或删除系统自带的ruby以及其环境变量

执行以下命令:

echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile

检查一下是否添加成功:

which ruby

若输出/usr/local/opt/[email protected]/bin/ruby说明添加成功。

查看一下目前ruby的版本:

ruby --version

若输出ruby 2.3.7p456说明新增的ruby安装成功。

2.3 更新gem

系统自带的ruby自带的gem路径:/usr/bin/gem

新增的ruby自带的gem路径:/usr/local/opt/[email protected]/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,专治各种终端恐惧症←_←

管理formulae.png
管理repo.png

步骤2.1中的[email protected]也可以通过cakebrew来安装:

安装ruby.png

最后不得不说一句,Homebrew大法好,Cakebrew你值得拥有

你可能感兴趣的:(pod setup失败解决方法)