我刚刚开始了一个react原生项目。然而,这个问题困扰了我一天。我尝试了所有可能的方法来解决它。例如,
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
此问题是由于Gemfile中指定的默认ruby
版本和ruby版本不同。要安装多个ruby版本,您必须在系统上安装rvm,然后安装多个rub版本。安装gem文件中指定的ruby版本之后。您必须运行bundle install
命令。链路
bundle install是一个命令,用于安装Gemfile中指定的依赖项。Gemfile简单地说,Gemfile是一种用于描述Ruby程序的gem依赖关系的格式。或者你可以说它包含了你在这个项目中需要的宝石。
之后,您可以安装并运行npx pod-install
或cd ios and pod install
pod install
工作之前的Bundle install
。
要回答Bundle Install,实际情况是,当生成react本机项目时,配置被设置为默认的macgem版本。如果你在mac上更新了gem版本,项目配置无法选择正确的gem版本。这就是它抛出can't find gem cocoapods
的原因。
通过执行Bundle install
,它将根据macgem版本更新项目配置。
安装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
如果您需要更新cocoapodsbrew upgrade cocoapods
pod setup