淘先锋技术网

首页 1 2 3 4 5 6 7

❓You don’t have write permissions for the /Library/Ruby/Gems/2.6.0 directory
❓问题原因:安装Cocoapods出现文件夹权限问题
🔧尝试解决:尝试通过超级管理员权限sudo解决(亲测无效❌)
🔧尝试解决:尝试通过重启关闭SIP解决(亲测无效❌)
结论:查阅相关资料后发现,macOS 13.0,目前不存在简单的直接解决方案(有另外特麻烦的直接解决方法),但是可以通过安装brew绕过权限问题 ☑️
解决方法:🔧安装brew
通过安装包管理器Homebrew(也可以称为brew),再通过brew安装Cocoapods,绕过权限问题
安装Homebrew,建议使用腾讯源(不行就换另外的源,有时候这个行,有时候那个行),使用常规安装脚本,命令行运行

苹果电脑 常规安装脚本(推荐 完全体 几分钟安装完成):
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

苹果电脑 极速安装脚本(精简版 几秒钟安装完成):
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.
  • Homebrew问题诊断,安装完成之后检查是否有问题,命令行运行,按照提醒依次运行解决问题,更新Xcode版本可以暂时不管

brew doctor

🔧安装ruby(不需要可以跳过到安装Cocopods步骤)

brew install ruby

检查ruby安装是否成功、查询相关安装目录

  • /usr/bin/ruby 为系统目录
  • which ruby
    输出结果:/usr/bin/ruby
    ruby -v
    输出结果:ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]
    

    配置ruby相关环境

  • 配置相关环境Path,使Brew安装的Ruby调用优先于系统的Ruby
  • intel芯片可以直接执行配置相关路径
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile

⚠️非intel芯片或者上面语句执行失败可以选择下面这个方法

  • 或者前往文件 ~/.zshrc,打开编辑添加相关语句(根据芯片类型选择)
  • intel芯片添加这个
    if [ -d "/usr/local/opt/ruby/bin" ]; then
      export PATH=/usr/local/opt/ruby/bin:$PATH
      export PATH=`gem environment gemdir`/bin:$PATH
    fi
    

  • apple芯片添加这个
  • if [ -d "/opt/homebrew/opt/ruby/bin" ]; then
      export PATH=/opt/homebrew/opt/ruby/bin:$PATH
      export PATH=`gem environment gemdir`/bin:$PATH
    fi
    

    🔧安装Cocopods

  • 通过brew安装Cocoapods
    brew install cocoapods
    

    检查Cocoapods是否安装成功,命令行运行,显示版本号则安装成功😄!

如果有这个提示   : You may want to remove it:   rm '/usr/local/bin/pod'

下面是我在Mojave机器上做的事情:

  • brew reinstall cocoapods
  • brew link --overwrite cocoapods,覆盖默认设置pod

$ brew reinstall cocoapods
==> Downloading https://homebrew.bintray.com/bottles/cocoapods-1.9.3.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/07/074e5b53b7a054c132582183dcf47546ddd028a7beb9fcdc653fe4a43225bcf3?__gda__=exp=1593894546~hmac=8b
######################################################################## 100.0%
==> Reinstalling cocoapods
==> Pouring cocoapods-1.9.3.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/pod
Target /usr/local/bin/pod
already exists. You may want to remove it:
  rm '/usr/local/bin/pod'

To force the link and overwrite all conflicting files:
  brew link --overwrite cocoapods

To list all files that would be deleted:
  brew link --overwrite --dry-run cocoapods

Possible conflicting files are:
/usr/local/bin/pod
/usr/local/bin/xcodeproj
==> Summary
?  /usr/local/Cellar/cocoapods/1.9.3: 12,705 files, 28.0MB

$ brew link --overwrite cocoapods
Linking /usr/local/Cellar/cocoapods/1.9.3... 2 symlinks created

ls检查安装和版本测试

$ ls -al $(which pod)
lrwxr-xr-x  1 rchen  staff  33 Jul  4 16:17 /usr/local/bin/pod -> ../Cellar/cocoapods/1.9.3/bin/pod

$ pod --version
1.9.3

成功了~