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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 12
- Comments: 57 (7 by maintainers)
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
.zshrc
file, [ quit and reopen your terminal after this, or source the.zshrc
file].ruby-version
on my home directory and then specified the ruby version required by react native to workworked like charm, hope it helps
I had the same problem when creating a new project in react-native. The solution I found was:
chsh -s /bin/zsh
” )./bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install rbenv ruby-build
nano ~/.zshrc
and when the file is opened add: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!you can leave the error, maybe there’s something wrong with cli.
just go to the project dir and execute
the project should running fine
for now, you can go to project dir and execute
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 versionInstall Ruby via RVM
Install RVM as per instructions
rvm install 2.7.6
// Or the one you need to addrvm --default use 2.7.6
// Or the one you need to addcan 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.
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
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/
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
: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 thoughruby --version
specifies 2.6.10 and rbenv shows I am using 2.7.5.(skip over obvious unrelated entries)
THANKS! It’s really worked.
我已执行该命令,但是得到的结果是准确的,直接执行shell也没有出现错误
我在失败之后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: