美文网首页
2021 pod安装以及问题整理

2021 pod安装以及问题整理

作者: 天下林子 | 来源:发表于2019-08-05 17:34 被阅读0次

前言

最近在使用pod,发现直接报错一大堆(ノへ ̄、)捂脸,在此整理一下2019年最新版本的安装以及遇到的问题

安装步骤

  • 如果你想直接卸载,用下面命令行:
#卸载
sudo gem uninstall cocoapods 

使用这个命令,如果你mac中装了很多pod 它会出现一个列表,让你选择,建议直接选择全部删除。

安装

pod安装其实很简单,就2个东西,一个是源,一个是ruby 然后就没了,看网上巴拉巴拉一大堆,呵呵哒
1.安装源

gem sources --remove https://rubygems.org/
gem sources -a https://gems.ruby-china.com/

2.ruby 环境
当你在更新mac系统的时候,ruby版本也会跟随着升级,命令行直接查看,ruby是2.3.7的,直接使用就可以了

lengwujudeMacBook-Pro:~ sfyh$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
lengwujudeMacBook-Pro:~ sfyh$ 

上面步骤好了之后,

lengwujudeMacBook-Pro:~ sfyh$ sudo gem install cocoapods
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.
    

这个地方报错了,看下错误信息是因为没权限,sudo安装,

Successfully installed xcodeproj-1.12.0
Fetching: fourflusher-2.3.1.gem (100%)
Successfully installed fourflusher-2.3.1
Fetching: cocoapods-1.7.5.gem (100%)
Successfully installed cocoapods-1.7.5
Parsing documentation for xcodeproj-1.12.0
Installing ri documentation for xcodeproj-1.12.0
Parsing documentation for fourflusher-2.3.1
Installing ri documentation for fourflusher-2.3.1
Parsing documentation for cocoapods-1.7.5
Installing ri documentation for cocoapods-1.7.5
Done installing documentation for xcodeproj, fourflusher, cocoapods after 5 seconds
3 gems installed

我以为装好了,然后pod看看,然后就蒙了。。

lengwujudeMacBook-Pro:~ sfyh$ pod --version
Ignoring ffi-1.9.25 because its extensions are not built.  Try: gem pristine ffi --version 1.9.25
/Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.5/lib/cocoapods/command.rb:118:in `git_version': Failed to extract git version from `git --version` ("xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun\n") (RuntimeError)
    from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.5/lib/cocoapods/command.rb:130:in `verify_minimum_git_version!'
    from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.5/lib/cocoapods/command.rb:49:in `run'
    from /Library/Ruby/Gems/2.3.0/gems/cocoapods-1.7.5/bin/pod:55:in `<top (required)>'
    from /usr/local/bin/pod:23:in `load'
    from /usr/local/bin/pod:23:in `<main>'
    

看上面的错误信息,它给了提示要执行gem pristine ffi --version 1.9.25,然后我试了下

lengwujudeMacBook-Pro:~ sfyh$ gem pristine ffi --version 1.9.25
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
    

没权限,sudo一下,报错了,信息如下:

lengwujudeMacBook-Pro:~ sfyh$ sudo gem pristine ffi --version 1.9.25
Password:
Restoring gems to pristine condition...
Building native extensions.  This could take a while...
ERROR:  While executing gem ... (Gem::Ext::BuildError)
    ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.9.25/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20190805-9538-jsrbjp.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.9.25 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.9.25/gem_make.out

上面这个报错,链接找不到了,我把解决报错的命令放下面:

lengwujudeMacBook-Pro:~ sfyh$ gem install bundler && rbenv rehash
Fetching: bundler-2.0.2.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
    

然后又会报错 You don't have write permissions for the /Library/Ruby/Gems/2.3.0 ,这个问题可以看下点我

继续:

lengwujudeMacBook-Pro:~ sfyh$ sudo gem install cocoapods --user-install
WARNING:  You don't have /Users/sfyh/.gem/ruby/2.3.0/bin in your PATH,
      gem executables will not run.
Successfully installed cocoapods-1.7.5
Parsing documentation for cocoapods-1.7.5
Installing ri documentation for cocoapods-1.7.5
Done installing documentation for cocoapods after 3 seconds
1 gem installed

到这个地方已经安装成功了,然后pod看下版本,

lengwujudeMacBook-Pro:~ sfyh$ pod --version
/Users/sfyh/.gem/ruby/2.3.0/gems/cocoapods-1.7.5/lib/cocoapods/command.rb:118:in `git_version': Failed to extract git version from `git --version` ("xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun\n") (RuntimeError)
    from /Users/sfyh/.gem/ruby/2.3.0/gems/cocoapods-1.7.5/lib/cocoapods/command.rb:130:in `verify_minimum_git_version!'
    from /Users/sfyh/.gem/ruby/2.3.0/gems/cocoapods-1.7.5/lib/cocoapods/command.rb:49:in `run'
    from /Users/sfyh/.gem/ruby/2.3.0/gems/cocoapods-1.7.5/bin/pod:55:in `<top (required)>'
    from /usr/local/bin/pod:23:in `load'
    from /usr/local/bin/pod:23:in `<main>'
lengwujudeMacBook-Pro:~ sfyh

看上面的报错是xcrun的问题,就是Xcode没有设置路径,

lengwujudeMacBook-Pro:~ sfyh$ xcrun
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
lengwujudeMacBook-Pro:~ sfyh$ xcrun --version
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

image.png

设置一下,再次pod 看下

lengwujudeMacBook-Pro:~ sfyh$ xcrun --version
xcrun version 47.
lengwujudeMacBook-Pro:~ sfyh$ pod --version
1.7.5

终于好了😂😂😂😂😂

还有一个问题纪录一下,报错信息如下:

ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.

解决方法如下:

sudo gem install -n /usr/local/bin cocoapods

更新于 2021年1月20号

报错信息如下:

WARNING:  You don't have /Users/cuilinhao/.gem/ruby/2.6.0/bin in your PATH,
      gem executables will not run.
Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
    ERROR: Failed to build gem native extension.

    current directory: /Users/cuilinhao/.gem/ruby/2.6.0/gems/ffi-1.14.2/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 ./siteconf20210120-1047-18i5w35.rb extconf.rb
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb:229: warning: Insecure world writable dir /usr/local/sbin in PATH, mode 040777
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi,/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ffi,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ffi... yes
checking for ffi_prep_closure_loc() in -lffi... yes
checking for ffi_prep_cif_var()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
creating extconf.h
creating Makefile

current directory: /Users/cuilinhao/.gem/ruby/2.6.0/gems/ffi-1.14.2/ext/ffi_c
make "DESTDIR=" clean
current directory: /Users/cuilinhao/.gem/ruby/2.6.0/gems/ffi-1.14.2/ext/ffi_c
make "DESTDIR="
make: *** No rule to make target `"/Applications/Xcode', needed by `AbstractMemory.o'.  Stop.
make failed, exit code 2
Gem files will remain installed in /Users/cuilinhao/.gem/ruby/2.6.0/gems/ffi-1.14.2 for inspection.
Results logged to /Users/cuilinhao/.gem/ruby/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.14.2/gem_make.out

  • 上面报错信息说的是ruby 路径有问题,解放方式如下:
    1.先确认Ruby的版本
    2.确认Ruby所在的路径
cuilinhaodeMacBook-Pro:~ cuilinhao$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
cuilinhaodeMacBook-Pro:~ cuilinhao$ which ruby
/usr/bin/ruby
cuilinhaodeMacBook-Pro:~ cuilinhao$ brew install ruby

  • 你可以用Homebrew安装最新的Ruby

  • ps:遇到一个奇葩的问题,就是安装Homebrew时,一直安装失败,你要先尝试打开这个链接看下是不是网络问题,如果一直打不开,那就gg了,那肿么办呢
    放大招了嘿嘿
    一行脚本搞定

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

你可以试试,如果还有问题看下这个文章

GO ON <<

  • 安装最新的Ruby 然后查看Ruby的位置
cuilinhaodeMacBook-Pro:~ cuilinhao$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
cuilinhaodeMacBook-Pro:~ cuilinhao$ which ruby
/usr/bin/ruby
cuilinhaodeMacBook-Pro:~ cuilinhao$ brew install ruby

重置PATH的,脚本如下:

$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/xxx/.bash_profile
$ echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"' >> ~/.bash_profile
$ echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.bash_profile

$ source ~/.bash_profile

  • 终端显示如下:
cuilinhaodeMacBook-Pro:~ cuilinhao$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/cuilinhao/.bash_profile
cuilinhaodeMacBook-Pro:~ cuilinhao$ echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"' >> ~/.bash_profile
cuilinhaodeMacBook-Pro:~ cuilinhao$ echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.bash_profile
cuilinhaodeMacBook-Pro:~ cuilinhao$ source ~/.bash_profile
cuilinhaodeMacBook-Pro:~ cuilinhao$ ruby -v
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin20]
cuilinhaodeMacBook-Pro:~ cuilinhao$ which ruby
/usr/local/opt/ruby/bin/ruby
cuilinhaodeMacBook-Pro:~ cuilinhao$ sudo gem install -n /usr/local/bin cocoapods
Password:
Fetching xcodeproj-1.19.0.gem
Fetching colored2-3.1.2.gem

按照步骤一步一步安装就OK

后续有问题再更新,评论区,可以留言互相交流~~😁😁😁

相关文章

网友评论

      本文标题:2021 pod安装以及问题整理

      本文链接:https://www.haomeiwen.com/subject/lgbmdctx.html