我刚刚开始一个react-native项目。然而这个问题却困扰了我一天。 我尝试了所有可能的方法来解决它。例如,
sudo gem uninstall cocoapods
rvm uninstall
brew install cocoapods
然而,我却没有运气。 我想指出的是,我可以在其他路径下
pod --version
,但是当我尝试在我的项目路径下 pod
时,会出现问题。我还尝试将rvm默认版本设置为2.7.5,但问题仍然发生。
另外,我没有使用Apple M1
Traceback (most recent call last):
4: from /Users/nicholas/.rvm/gems/ruby-2.7.5/bin/ruby_executable_hooks:22:in `<main>'
3: from /Users/nicholas/.rvm/gems/ruby-2.7.5/bin/ruby_executable_hooks:22:in `eval'
2: from /Users/nicholas/.rvm/gems/ruby-2.7.5/bin/pod:23:in `<main>'
1: from /Users/nicholas/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/rubygems.rb:296:in `activate_bin_path'
/Users/nicholas/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
尝试在项目的根目录中运行
bundle install
。然后转到 ios
并运行 pod install
或使用项目根目录中的 npx pod-install
。
去除可可足类:
sudo gem uninstall cocoapods
然后再次安装:
sudo gem install -n /usr/local/bin cocoapods
此问题是由于您的默认
ruby
版本与 Gemfile 中指定的 ruby 版本不同造成的。要安装多个 ruby 版本,您必须在系统上安装 rvm,然后安装多个 ruby 版本。安装 gem 文件中指定的 ruby 版本后。你必须运行 bundle install
命令。 链接
bundle install 是我们用来安装 Gemfile 中指定的依赖项的命令。 宝石文件 简单来说,Gemfile 是一种用于描述 Ruby 程序的 gem 依赖关系的格式。或者你可以说它包含了你在这个项目中需要的宝石。
此后您可以安装运行
npx pod-install
或cd ios and pod install
Bundle install
在 pod install
工作之前。
回答 Bundle Install 的问题是,在生成 React Native 项目时,配置被设置为默认的 mac gem 版本。如果您在 Mac 上更新了 gem 版本,则项目配置无法选择正确的 gem 版本。这就是为什么它会抛出
can't find gem cocoapods
。
通过执行
Bundle install
,它将根据mac gem版本更新项目配置。
安装Brew
curl -fsSL -o install.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
/bin/bash install.sh
brew install chruby ruby-install
brew install cocoapods
如果您需要更新cocoapods
brew upgrade cocoapods
pod setup