1、新的电脑基本上都已经安装好最新的ruby了,不放心的可以检查一下ruby的版本和sources,
ruby -v
gem sources -l
2、查看Homebrew:
brew -v
2.1)MacOs M1安装Homebrew:
/bin/zsh -c "$(curl -fsSL https://gitee.com/huwei1024/HomebrewCN/raw/master/Homebrew.sh)"
3、验证你的Ruby镜像是并且仅是ruby-china,执行以下命令查看:
gem sources -l
3.1)查看结果;
*** CURRENT SOURCES ***
https://gems.ruby-china.com/
4、这时候才正式开始安装CocoaPods:
sudo gem install -n /usr/local/bin cocoapods
5、安装好了之后 如果执行pod install 报错 可能是因为没有勾选使用Rosetta打开 (应用程序-实用工具-终端-显示简介-勾选“Rosetta”)
就执行
sudo arch -x86_64 gem install ffi
等待安装好之后也可能是告诉你没有读写/usr/bin的权限,执行
sudo gem install cocoapods -n /usr/local/bin
6、然后就可以
pod install
执行 arch -x86_64 pod install
卸载coccapods
$ sudo gem uninstall cocoapods【Mac 10.10之前】
$ sudo gem uninstall -n /usr/local/bin cocoapods【Mac 10.11之后】
统一删除:$ gem uninstall cocoapods cocoapods-core cocoapods-deintegrate cocoapods-downloader cocoapods-plugins cocoapods-search cocoapods-trunk cocoapods-try
查看cocoapods本地相关:
输入:gem list --local | grep cocoapods
打印:
cocoapods-core (0.39.0)
cocoapods-downloader (0.9.3)
cocoapods-plugins (0.4.2)
cocoapods-search (0.1.0)
cocoapods-stats (0.6.2)
cocoapods-trunk (0.6.4)
cocoapods-try (0.5.1)
然后逐个删除吧:
$ sudo gem uninstall cocoapods-core【Mac 10.10之前用这个】
$ sudo gem uninstall -n /usr/local/bin cocoapods-core【Mac 10.11之后用这个】
后面重新整理了(新电脑mac M1装cocoapods)
终端要勾选使用Rosetta打开 (应用程序-实用工具-终端-显示简介-勾选“Rosetta”)
cocoapods安装
新的电脑基本上都已经安装好最新的ruby了,不放心的可以检查一下ruby的版本和sources
一、检查ruby源
输入:gem sources -l
打印:(新电脑默认不是china,需要移除添加)
*** CURRENT SOURCES ***
https://gems.ruby-china.com
移除ruby:
移除输入:gem sources --remove https://rubygems.org/
移除后添加源:输入:gem sources --add https://gems.ruby-china.com
查看是否添加成功:输入:gem sources -l
二、homebrew安装
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
若不行尝试这个地址:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
三、检查Mac是否安装了rvm
输入:rvm -v
打印:command not found:未安装
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [RVM: Ruby Version Manager - RVM Ruby Version Manager - Documentation]:已安装
安装成功:打印:rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]
安装rvm:
输入:
curl -L get.rvm.io | bash -s stable
(注:安装后退出终端再输入:rvm -v查看是否安装成功)
若报错:curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 2 ms: Connection refused,执行5.4步骤
若还报错执行5.9和5.9.1后再执行安装rvm
四、列出所有指定源里的ruby版本
输入:rvm list known
打印:
aisen@AisendeMac-mini ~ % rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0]
ruby-head
安装最新的版本:输入:rvm install 3.0.0
打印:
Searching for binary rubies, this might take some time.
Checking requirements for osx.
Installing requirements for osx.
Updating system - please wait
…
ruby-3.0.0 - #generating default wrappers - please wait
ruby-3.0.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
Install of ruby-3.0.0 - #complete
Ruby was built without documentation, to build it run: rvm docs generate-ri
检查安装版本:输入:rvm list
五:安装cocapods
5.1 输入:sudo gem install -n /usr/local/bin cocoapods
打印:Installing ri documentation for algoliasearch-1.27.5
…..
34 gems installed
5.2 查看当前版本:pod --version
5.3 测试:pod search AFNetworking
出现报错:[!] Unable to find a pod with name, author, summary, or description matching `afnetworking`
pod install
也报错:[!] Couldn't determine repo type for URL: `https://github.com/CocoaPods/Specs.git`: Failed to open TCP connection to github.com:443 (Connection refused - connect(2) for "github.com" port 443)
5.4 修改host文件并加入github.com的IP地址:
注:这部可以放在最前面操作(如果前面操作有报错:Connection refused, timeout)
打开文件etc(前往/etc)修改host文件,host复制到桌面后修改加入github.com的ip地址,即:获取ip:https://ipaddress.com/website/github.com 后得到:140.82.112.4 github.com,搜索raw.githubusercontent.com找到对应的IP地址,该栏目没有的话,滑到最底下DNS Records的第一个IP(185.199.108.133),然后替换etc文件的host
5.5 再重新试:pod search AFNetworking
成功就忽略以下步骤
5.6 还报错,终端依次执行:1、pod repo remove master
2、 cd ~/.cocoapods/repos
3、 git clone --depth 1 https://github.com/CocoaPods/Specs.git master
打印:
5.7 完成后再测试:pod search AFNetworking
成功后下忽略
5.8 输入:
sudo arch -x86_64 gem install ffi
sudo gem install ffi
5.9 如果执行pod install 报错 可能是因为没有勾选使用Rosetta打开 (应用程序-实用工具-终端-显示简介-勾选“Rosetta”)
就执行
sudo arch -x86_64 gem install ffi
5.9.1 报没有读写/usr/bin的权限,则执行
sudo gem install cocoapods -n /usr/local/bin
以上以安装完毕了!!!!!!!!
平时更新库报错时:执行:sudo gem install xcodeproj
### Command```
/Users/weya/.rvm/rubies/ruby-3.0.0/bin/pod install
### Report
* What did you do?
* What did you expect to happen?
* What happened instead?
### Stack
CocoaPods : 1.12.1
Ruby : ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin21]
RubyGems : 3.4.18
Host : macOS 12.6 (21G115)
Xcode : 14.2 (14C18)
Git : git version 2.37.1 (Apple Git-137.1)
Ruby lib dir : /Users/weya/.rvm/rubies/ruby-3.0.0/lib
/.....
Looking for related issues on cocoapods/cocoapods...
- Pod init in xcode 14.1 and mac os ventura 13.0.1
2025.02.10更新:(cocoapods 查看版本报错pod --version)
cocoapods 报错:
...rvm/rubies/ruby-3.0.0/lib/ruby/gems/3.0.0/gems
…
.rvm/rubies/ruby-3.0.0/bin/ruby_executable_hooks:22:in <main>'
尝试安装ruby3.2.0版本
~ % rvm install 3.2.0
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/15.1/x86_64/ruby-3.2.0.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Installing requirements for osx.
Updating system - please wait
Installing required packages: pkg-config - please wait
==> Upgrading 1 outdated package:
openssl@1.1 1.1.1s -> 1.1.1w
Error: openssl@1.1 has been disabled because it is not supported upstream! It was disabled on 2024-10-24.
Requirements installation failed with status: 1.
openssl@1.1 已被弃用且不再支持,因此你无法继续安装 Ruby 3.2.0。
解决方法:👇
1、为了避免 RVM 使用 openssl@1.1,你可以首先卸载它:
brew uninstall openssl@1.1
2、虽然卸载了 openssl@1.1,但有一些配置文件可能仍然存在。如果你希望彻底清理这些文件,可以执行:
rm -rf /usr/local/etc/openssl@1.1
rm -rf /usr/local/etc/openssl@1.1/cert.pem
rm -rf /usr/local/etc/openssl@1.1/certs
rm -rf /usr/local/etc/openssl@1.1/ct_log_list.cnf
rm -rf /usr/local/etc/openssl@1.1/ct_log_list.cnf.dist
rm -rf /usr/local/etc/openssl@1.1/misc
rm -rf /usr/local/etc/openssl@1.1/misc/CA.pl
rm -rf /usr/local/etc/openssl@1.1/misc/tsget
rm -rf /usr/local/etc/openssl@1.1/misc/tsget.pl
rm -rf /usr/local/etc/openssl@1.1/openssl.cnf
rm -rf /usr/local/etc/openssl@1.1/openssl.cnf.dist
rm -rf /usr/local/etc/openssl@1.1/private
3、安装openssl@3:
brew install openssl@3
4、你已经安装了 openssl@3,并且之前已经设置了环境变量。再次确认并设置环境变量指向 openssl@3:
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig"
5、现在,尝试再次安装 Ruby 3.2.0 并确保它使用 openssl@3:
rvm install 3.2.0 --with-openssl-dir=/opt/homebrew/opt/openssl@3
查看版本:
ruby -v
输出:ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-darwin24]
6、查看pod版本:
pod --version
如输出:.rvm/rubies/ruby-3.2.0/lib/ruby/3.2.0/rubygems.rb:265:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
安装cocoapods输入: gem install cocoapods
尝试 pod search Gifu