安装pod时,报无写入权限的错误:
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin21/rbconfig.rb:230: warning: Insecure world writable dir /opt/homebrew/opt in PATH, mode 040777
While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
解决方法:
1.有文章说使用如下代码即可解决,但未起效:
sudo gem install -n /usr/local/bin cocoapods
2.也有说是权限问题:
提示含义:
目录被赋予777的权限,不安全。
如何解决:
将提示权限改为775,问题即可解决。
解决方法:
sudo chmod go-w /usr/local/bin
sudo chmod 775 /usr/local
3.有说是安全机制问题(https:/blog.csdn.net/SharkToping/article/details/79464581),试过后未生效。
4.最终发现是路径问题:
(1)首先使用homebrew安装ruby:
$ brew install ruby
(2)设置环境并应用:
$ 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
注意:第一行代码中的xxx一定要是用户中的用户文件名,之前的报错就是路径不对导致的
(3)检查环境
$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ which ruby
/usr/local/opt/ruby/bin/ruby
(4)安装cocoapods
$ sudo gem install -n /usr/local/bin cocoapods