react-native icon indicating copy to clipboard operation
react-native copied to clipboard

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

Open caixingyue opened this issue 2 years ago • 30 comments

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

caixingyue avatar Oct 22 '22 14:10 caixingyue

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

caixingyue avatar Oct 22 '22 14:10 caixingyue

Lokk at the output of which ruby if which ruby does not point at a shims directory inside your homedirectory you might need to add if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi to your .bash_profile or .zshrc

this will setup rbenv on startup of your shell. If you have that line then look out for errors displayed at shell startup which might prevent it from running.

atkaygro avatar Oct 24 '22 16:10 atkaygro

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,并没有出现这个异常,所以我很奇怪

caixingyue avatar Oct 24 '22 16:10 caixingyue

but got error Your Ruby version is 2.6.8, but your Gemfile specified 2.7.5 failure message.

You're clearly running the wrong ruby version. You should be on Ruby 2.7.5 for React Native to run correctly.

cortinico avatar Oct 24 '22 17:10 cortinico

What is the output of ruby --version Try running ruby version 3.0.4.

atkaygro avatar Oct 25 '22 06:10 atkaygro

but got error Your Ruby version is 2.6.8, but your Gemfile specified 2.7.5 failure message.

You're clearly running the wrong ruby version. You should be on Ruby 2.7.5 for React Native to run correctly.

Yes, obviously my version is correct, but at init, it tells me that my version is wrong again, I don't understand why. image

caixingyue avatar Oct 25 '22 15:10 caixingyue

What is the output of ruby --version Try running ruby version 3.0.4.

react-native official documentation shows that I need to use ruby 2.7.5 version, installing 3.0.4 does not work.

image

I tried switching to the ruby 3.0.4 version and it shows that the result is indeed invalid.

image

caixingyue avatar Oct 25 '22 16:10 caixingyue

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?

robbiesmith79 avatar Oct 25 '22 17:10 robbiesmith79

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

ddikodroid avatar Oct 26 '22 03:10 ddikodroid

What is the output of ruby --version Try running ruby version 3.0.4.

react-native official documentation shows that I need to use ruby 2.7.5 version, installing 3.0.4 does not work.

image

I tried switching to the ruby 3.0.4 version and it shows that the result is indeed invalid.

image

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 as long as your ruby version is same with the recommended version

ddikodroid avatar Oct 26 '22 03:10 ddikodroid

What is the output of ruby --version Try running ruby version 3.0.4.

react-native official documentation shows that I need to use ruby 2.7.5 version, installing 3.0.4 does not work. image I tried switching to the ruby 3.0.4 version and it shows that the result is indeed invalid. image

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 as long as your ruby version is same with the recommended version

This method solves the problem and the project runs fine.

But every time a project is initialized, it needs to be run once, which is very cumbersome and cannot solve the fundamental problem. I am looking for a way to solve the fundamental problem, that is, it can run smoothly during npx react-native init.

caixingyue avatar Oct 26 '22 03:10 caixingyue

Since you are running on M1 there might be something wrong with architecture handling: If you spawn a shell using something similar to arch -arch x86_64 bash everything run from the new shell will think, its running on intel, so running arch on the new shell should yield x86_64. Try installing ruby 2.7.5 (and react-native cli) from that and see if that helps.

atkaygro avatar Oct 26 '22 06:10 atkaygro

You can change ruby version in Gemfile, and then

  1. bundle install
  2. cd ios
  3. bundle exec pod install

gonefish avatar Oct 26 '22 07:10 gonefish

Since you are running on M1 there might be something wrong with architecture handling: If you spawn a shell using something similar to arch -arch x86_64 bash everything run from the new shell will think, its running on intel, so running arch on the new shell should yield x86_64. Try installing ruby 2.7.5 (and react-native cli) from that and see if that helps.

As you can see, I cannot install this project, I have tried to resolve this error, but failed. my device is macbook air m1 version. image

caixingyue avatar Oct 27 '22 14:10 caixingyue

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.

Sun-SunQian avatar Oct 27 '22 15:10 Sun-SunQian

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

ddikodroid avatar Oct 27 '22 22:10 ddikodroid

I am having the same problem. This seems to be an issue for Mac users. If it is confirmed that version 2.6.8 is not used when both "which ruby" and "ruby --version" commands are used, react-native init seems to use Mac's pre-install ruby. (/usr/bin/ruby)

abelbeak avatar Oct 28 '22 01:10 abelbeak

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

yes, this solved my problem, thanks a lot! But the init is still failing.

Sun-SunQian avatar Oct 28 '22 02:10 Sun-SunQian

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/

Romefjp avatar Oct 28 '22 05:10 Romefjp

@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:

Romefjp avatar Oct 28 '22 06:10 Romefjp

I'm having the same problem. I'm using M1 Macbook Pro.

eagle-head avatar Oct 28 '22 21:10 eagle-head

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

Still I am getting this issue

image

My ruby version is : which ruby /Users/praveekumar/.rbenv/shims/ruby

praveenkumar66 avatar Oct 31 '22 12:10 praveenkumar66

Same issue with intel macbook pro

sccox avatar Nov 01 '22 18:11 sccox

I have the same issue, my current ruby version is 2.7.6 and still getting the error, I tried version 2.7. as well and still have the same error Screenshot 2022-11-02 at 11 58 28 Screenshot 2022-11-02 at 11 59 41

moatazeldebsy avatar Nov 02 '22 11:11 moatazeldebsy

I have the same issue, my current ruby version is 2.7.6 and still getting the error, I tried version 2.7. as well and still have the same error Screenshot 2022-11-02 at 11 58 28 Screenshot 2022-11-02 at 11 59 41

Hi, try for now, you can go to project dir and execute

bundle install cd ios && bundle exec pod install

This solved the problem for me.

Sun-SunQian avatar Nov 02 '22 11:11 Sun-SunQian

yes it works thank you, I'm just confirming that I have the same issue with the CLI

moatazeldebsy avatar Nov 02 '22 11:11 moatazeldebsy

I was having the same issue and then followed this steps and it seems to work now. Maybe it was because i didn't have NVM installed. Hope it can help someone else too.

antonioestebanlozano avatar Nov 02 '22 20:11 antonioestebanlozano

I also used the latest node version 18.12.0 not the one specified in the link I posted.

antonioestebanlozano avatar Nov 02 '22 20:11 antonioestebanlozano

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

elliotmrodriguez avatar Nov 04 '22 15:11 elliotmrodriguez

I got the same problem, but when I try your fix with

bundle install
cd ios && bundle exec pod install

a vendor folder is generated... this never before happened, when i made a react-native project... anybody knows why this happens or what i have done wrong? My steps where:

npx react-native init ReactNativeApp --template react-native-template-typescript
bundle install
cd ios && bundle exec pod install

image

remllov91 avatar Nov 07 '22 13:11 remllov91

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!

Jedaesla avatar Nov 09 '22 23:11 Jedaesla