简体   繁体   中英

React Native init Project

which ruby outputs -> /Users/User/.rbenv/shims/ruby

ruby -v outputs -> ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-darwin21]

which bundle outputs -> /Users/User/.rbenv/shims/bundle

bundle -v outputs -> Bundler version 2.1.4

but the problem is that npx react-native init MyProject outputs -> ✖ Installing Bundler error Bundler::RubyVersionMismatch: Your Ruby version is 2.6.10, but your Gemfile specified 2.7.5

What's likely happening is that npx react-native init MyProject is sub-shelling into Bash where you do not have rbenv configured. When it tries to run ruby from Bash it looks in $PATH and finds the default macOS version of Ruby -- 2.6.10 -- and errors out.

This is discussed thoroughly in the react-native repo where there are many solutions, but what it boils down to is react-native init is not finding the right version of Ruby, for whatever reason. You can bypass that by completing the failing part of the init process yourself with:

cd MyProject
bundle install
cd ios && bundle exec pod install

The longer version of the solution is to configure rbenv for Bash as well, but this isn't necessary as you can likely use just the workaround above:

echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bash_profile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM