先是执行:sudo gem install cocoapods
报错:
ERROR: Error installing cocoapods:
The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.3. Try installing it with `gem install activesupport -v 6.1.7.3` and then running the current command again
activesupport requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
看起来是要更新Ruby版本,所以执行命令:
sudo gem update --system
报错:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/gem
应该是没有权限还是什么,然后执行:
sudo gem update -n usrlocalbin --system
成功升级。
接下来安装cocoapods,输入命令:
sudo gem install cocoapods
报错:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory.
应该是没有权限还是什么,再试其他方式:
sudo gem install -n /user/local/bin cocoapods
继续报错:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0 directory.
再试:
sudo gem install cocoapods --user-install
搞定:
提示安装成功,但是注意有个WARNING:
You don't have /Users/a1/.local/share/gem/ruby/2.6.0/bin in your PATH,
gem executables will not run.
这时候执行pod相关命令的时候会提示:
zsh: command not found: pod
我的解决方法:
执行以下命令:(参考:iMac安装pod遇到的问题 - 简书)
export PATH="/Users/xxx/.local/share/gem/ruby/2.6.0/bin":$PATH
其中xxx是你用户文件名,比如我的是a1:
所以就是
export PATH="/Users/a1/.local/share/gem/ruby/2.6.0/bin":$PATH
全部搞定!!