环境:
Mac: 14.5 (23F79)
芯片:Apple M2
我的安装步骤:
1.用ruby安装cocoapods时,先安装rvm :
curl -L get.rvm.io | bash -s stable
source ~/.bashrc
source ~/.bash_profile
我的rvm版本:rvm 1.29.12
2.安装ruby, rvm install 3.3.1, 安装ruby -v: ruby 3.3.1 (2024-04-23 revision c56cd86388) [arm64-darwin23]
3.更新gem,sudo gem update --system,完了后添加新源gem sources--addhttps://gems.ruby-china.com/,
但是查看源发现啥源都没有,去安装cocoapods时就会报错:
ERROR:Whileexecuting gem...(Gem::Exception)OpenSSL is not available.Install OpenSSLandrebuild Ruby(preferred)orusenon-HTTPSsources
说openssl不可用,这是因为 ruby 没有编译 OpenSSL 支持,
这里有个坑openssl 3会有问题,只有重新安装带有openssl 1.1支持的 ruby 后它才有效。(https://www.jianshu.com/p/755584737ce0)。解决办法:
// install openssl@1.1
brew install openssl@1.1
// export PKG_CONFIG_PATH variable
export PKG_CONFIG_PATH=/opt/homebrew/opt/openssl@1.1/lib/pkgconfig
// reinstall your ruby version with openssl 1.1 dir
rvm reinstall 3.3.1 --with-openssl-dir=/opt/homebrew/opt/openssl@1.1
因为我的openssl安装在/opt/homebrew/bin/openssl,可which openssl查看,所以上面的rvm重新安装依赖的路径要给对才会起作用!
4.然后再去添加源后查看就有了,然后sudo gem install -n /usr/local/bin cocoapods,安装成功!