How to fix "error Your Ruby version is 2.6.8, but your Gemfile specified 2.7.6" in React Native

How to fix "error Your Ruby version is 2.6.8, but your Gemfile specified 2.7.6" in React Native

I encountered this issue when I was trying to spin up a new React Native project. This is how I fixed it.

  • First, update brew
brew update
  • Use brew to install ruby-build
brew install ruby-build
  • Use brew to install rbenv
brew install rbenv
  • Then go ahead to install the rbenv version you need. In our case, it is version 2.7.6
rbenv install 2.7.6
  • Next, set the new version to be global
rbenv global 2.7.6
  • Finally, export the following configurations to define rbenv as default global ruby
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
  • And
echo 'eval "$(rbenv init -)"' >> ~/.zshrc

Finally kill the terminal and restart it.
Now you can succesfully create a new React Native project.