react-native: npx react-native init could not be done properly, it may be something missing from the system

Description

I initialized by command react-native init name, but got error Your Ruby version is 2.6.8, but your Gemfile specified 2.7.5 failure message.

I have tried deleting .npm, uninstalling and reinstalling rbenv and gem, etc., and all of them have been cleaned up. I have re-deployed step by step according to the official website tutorial, but none of them have failed.

The current directory ruby version is 2.7.5, and the global directory ruby version 2.7.5 also cannot solve this problem.

Version

0.70.3

Output of npx react-native info

info Fetching system and libraries information… System: OS: macOS 12.6 CPU: (8) arm64 Apple M1 Memory: 114.22 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.10.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 8.19.2 - /usr/local/bin/npm Watchman: 2022.10.17.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /Users/caixiaorui/.rbenv/shims/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9123335 Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild Languages: Java: 11.0.17 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.3 => 0.70.3 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

react-native init name

Snack, code example, screenshot, or link to a repository

image image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 12
  • Comments: 57 (7 by maintainers)

Most upvoted comments

if you still have this issue here is how I solved it

I’m on MacBook Pro M2, with Mac Osx Ventura 13.0.1

  1. Uninstalled cocoapods
brew uninstall --force cocoapods
  1. Uninstalled ruby, because I had 3.1.2 installed, along with 2.6 which comes pre installed by Mac
brew uninstall --force ruby
  1. I installed rbenv
brew install rbenv
  1. I installed the required ruby version with rbenv
rbenv install 2.7.5
  1. I added this code to my .zshrc file, [ quit and reopen your terminal after this, or source the .zshrc file]
eval "$(rbenv init - zsh)"
  1. I created this file .ruby-version on my home directory and then specified the ruby version required by react native to work
touch ~/.ruby-version
echo 2.7.5  > ~/.ruby-version

## test if the version is the one you want by running
ruby -v
  1. Run the command to initialise the project
npx react-native init RNapp --template react-native-template-typescript

worked like charm, hope it helps

I had the same problem when creating a new project in react-native. The solution I found was:

  1. All processing must be done in the zsh shell and not the bash shell. (to switch from bash to zsh, use -> “chsh -s /bin/zsh” ).
  2. Have Homebrew installed with your command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  3. install rbenv: brew install rbenv ruby-build
  4. Add two lines of code to the .zshrc file either by editing the file directly or using nano with the command: nano ~/.zshrc and when the file is opened add:
# Customize to your needs...
export PATH=$HOME/.rbenv/bin:/usr/local/bin:$HOME/.bin:$PATH
# load rbenv automatically
eval "$(rbenv init - zsh)"

reference of this file: https://gist.github.com/seancdavis/9975387 control o, enter and control x to save and close in nano 5. it can be given right there in the console: source ~/.zshrc to load the file or better yet close the console and reopen it, all with the purpose that whenever a terminal is opened the new configuration is loaded. 6. check the ruby ​​version in the console with: ruby ​​-v in my case it showed the one that caused the error so the requested version must be installed, in my case 2.7.5 7 install the new version of ruby ​​with the command: rbenv install 2.7.5 this downloads the new compatible version 8. Change the system version to the downloaded version with the command: rbenv global 2.7.5 9. We verify again the version of ruby ​​has changed with the command: ruby ​​-v If the version changed, you can freely go to create the react-native project!

I’m getting the same error. I did which ruby and it listed my rbenv/shims/ruby. I’ve updated my .bash_profile and .zshrc. I have confirmed my version is actually 2.7.5 but the npx react-native init still oddly thinks I’m using 2.6.8. I’m not. What am I missing?

you can leave the error, maybe there’s something wrong with cli.

just go to the project dir and execute

bundle install
cd ios && bundle exec pod install

the project should running fine

bundle install cd ios && bundle exec pod install

for now, you can go to project dir and execute

bundle install
cd ios && bundle exec pod install

I am having the same issue with Mac intel chips. ruby -v shows the correct ruby version, but running the project keeps on getting the same error message as you do. I have tried rvm and rbenv, none of them work.

For those of you having problems with your Ruby version, this worked for me:

Uninstallation

brew uninstall ruby // for removing brew version

Install Ruby via RVM

Install RVM as per instructions

rvm install 2.7.6 // Or the one you need to add

rvm --default use 2.7.6 // Or the one you need to add

can use rvm list to see available ruby versions.

It worked normally at first, but I don’t know what was deleted, which caused this problem. Then no matter what I do, I can’t solve the problem

Hello, everyone!

I’m on MacBook M1 16 Pro, with Mac Os Ventura 13.0.1

This issue still makes me crazy. But I found a strange solution which finally helped me:

just add @0.69 after react-native init:

npx react-native@0.69 init App

or npx react-native@0.69 init App --template react-native-template-typescript

but as the result in package.json RN version is above 0.70. Don’t ask me why.

Screenshot 2022-11-27 at 09 41 10

p.s. I tried all these solutions above but nothing helped me.

I’m getting the same error. I did which ruby and it listed my rbenv/shims/ruby. I’ve updated my .bash_profile and .zshrc. I have confirmed my version is actually 2.7.5 but the npx react-native init still oddly thinks I’m using 2.6.8. I’m not. What am I missing?

the reason why it doesn’t detect the new Ruby version because

  • react native depends on
    • @react-native-community which depends on
      • execa which add /usr/local/bin before your $PATH and if bundle (this one related to the default ruby exist on the system) exist inside this folder it will be prioritized

so i suggest to delete /usr/local/bin/bundle

For me, works with $ rvm install ruby-2.7.5 $ rvm use 2.7.5

In the documentation say “Currently, macOS 12.5.1 is shipped with Ruby 2.6.8, which is not what is required by React Native. Our suggestion is to install a Ruby version manager and to install the proper version of Ruby in your system.” https://rvm.io/

bundle install cd ios && bundle exec pod install

for now, you can go to project dir and execute

bundle install
cd ios && bundle exec pod install

Thanks for this worked. For some reasons react-native cli having issues with pod and bundler also can’t spot default ruby version.

The above manual approach worked.

Thanks again

Faced the same problem. The rbenv global 2.7.5 command did not help, but I found the path to the folder where version 2.7.5 was installed (in my case is was /Users/alex/.rbenv/versions/2.7.5) and manually added it to ~/.bash_profile:

export PATH="/Users/alex/.rbenv/versions/2.7.5/bin:$PATH"

After that, the creation of a new project was successful.

proposed solution does not work for me. I am using rbenv, and I am also on an M1.

From the root of my project I’ve specified to use 2.7.5. If I try to run bundle install from here, I get complaints about 2.6.10 ruby version.

If I try to instead run bundle exec pod install from the ios directory, I get another complaint about using 3.1.2, even though ruby --version specifies 2.6.10 and rbenv shows I am using 2.7.5.

(skip over obvious unrelated entries)

image

Hello, everyone!

I’m on MacBook M1 16 Pro, with Mac Os Ventura 13.0.1

This issue still makes me crazy. But I found a strange solution which finally helped me:

just add @0.69 after react-native init:

npx react-native@0.69 init App

or npx react-native@0.69 init App --template react-native-template-typescript

but as the result in package.json RN version is above 0.70. Don’t ask me why.

Screenshot 2022-11-27 at 09 41 10

p.s. I tried all these solutions above but nothing helped me.

THANKS! It’s really worked.

which ruby 如果 which ruby​​ 没有指向主目录中的 shims 目录,则输出 Lokk,您可能需要将其添加 if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi 到 .bash_profile 或 .zshrc

这将在你的 shell 启动时设置 rbenv。 如果您有该行,请注意在 shell 启动时显示的错误,这可能会阻止它运行。

我已执行该命令,但是得到的结果是准确的,直接执行shell也没有出现错误 image

我在失败之后cd进入目录并且执行bundle install 后可以正常使用,但是在init时仍然会出现这个异常

我尝试过在其它电脑上测试init,并没有出现这个异常,所以我很奇怪

@abelbeak

I have M1

You may want to know more than the Ruby version number. You may want to know how Ruby was installed and where Ruby is installed. The which command will show you.

You can use the which command with flag -a to see if more than one Ruby executable is installed and where they are installed: