user19517977
user19517977

Reputation:

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

Upvotes: 1

Views: 257

Answers (1)

anothermh
anothermh

Reputation: 10554

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

Upvotes: 0

Related Questions