Mac Pro M2安装使用Cocoapods
在新公司要做iOS开发,所以在新电脑上安装Cocoapods
在升级gem,sudo gem update --system,和安装cocoapods时都遇到如下的提示:
            
            
              bash
              
              
            
          
          ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted @ rb_sysopen - /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/gem原因大概是:Apple已内置安装了ruby,不能修改
参考:
the reason why you are getting that error is because Apple doesn't allow you to install gems directly into the version of Ruby that came preinstalled on your Mac
其中的一个解决办法就是,可通过安装ruby版本管理器来解决,如chruby或者RVM
安装chruby
            
            
              bash
              
              
            
          
          brew install ruby-install chruby安装后按提示,在.zshrc 中写入如下的内容:
            
            
              bash
              
              
            
          
          source /opt/homebrew/opt/chruby/share/chruby/chruby.sh
source /opt/homebrew/opt/chruby/share/chruby/auto.sh
chruby ruby-3.1.2然后安装Ruby,如下的代码安装并使用最新的ruby
            
            
              bash
              
              
            
          
          ruby-install --latest ruby安装之前看下当前系统的ruby的版本:
            
            
              bash
              
              
            
          
          ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]SwitchHosts
在安装过程中,可能会提示raw.githubusercontent.com网站的内容不能访问,此时需要配置host,推荐安装SwitchHosts
host配置如下:
            
            
              bash
              
              
            
          
          185.199.110.133  raw.githubusercontent.com或者参考:
配置一个远程的,自动更新的host
然后可能需要重启系统才生效。继续执行ruby-install --latest ruby
chruby
参考:
使用chruby命令列出可用的ruby

使用chruby 3.2.2,选择3.2.2的版本

cocoapods
参考官方文档:
安装cocoapods
            
            
              bash
              
              
            
          
          sudo gem install cocoapodscocoapods镜像
原始源地址为https://github.com/CocoaPods/Specs.git
            
            
              bash
              
              
            
          
          $ cd ~/.cocoapods/repos 
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master最后进入自己的工程,在自己工程的podFile第一行加上:
            
            
              bash
              
              
            
          
          source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'ruby镜像
移除现有的Ruby镜像
            
            
              bash
              
              
            
          
           gem sources --remove https://rubygems.org/添加清华的镜像,参考Ruby Gems 镜像使用帮助
            
            
              bash
              
              
            
          
          # 添加镜像源并移除默认源
gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/
# 列出已有源
gem sources -l
# 应该只有镜像源一个gem
gem相关,可参考:
查看gem版本:
            
            
              bash
              
              
            
          
          gem -v遇到的问题
1.pod install时提示HTTP/2 stream 1 was not closed cleanly before end of the underlying stream

按网络上的说法解决:
            
            
              bash
              
              
            
          
          git config --global http.version HTTP/1.1其他
可参考: