214

I am getting -bash: react-native: command not found error while creating a react-native project.

Below are the additional info

1. brew --version
   homebrew 0.9.9
2  brew info watchman
   watchman `enter code here`stable 4.50
   /usr/local/Cellar/watchman/4.4.0
3. brew info flow
   stable 0.24.1
   /usr/local/Cellar/flow/0.24.1
4. brew info node
   stable 6.1.0
   /usr/local/Cellar/node/6.1.0
5. npm -version
   3.8.6
6. echo $PATH
/Users/Ashok/.rbenv/shims:/Users/Ashok/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

I tried the suggested steps from this link but I am still getting the same error.

I don't have any "npm" directory which they have specified in the solution

Ashoks-MacBook-Pro:share Ashok$ ls
aclocal     doc     info        ruby-build  zsh
autoconf    emacs       man     systemtap

But I found npm file exists in the below location.

/usr/local/Cellar/node/6.1.0/etc/bash_completion.d

I uninstalled react-native and installed it again but I am still facing the same issue.

5
  • 41
    Have you tried npm i -g react-native-cli instead of npm i -g react-native ? Commented May 12, 2016 at 13:56
  • 3
    i am using "sudo npm install -g react-native-cli"
    – Ashok R
    Commented May 12, 2016 at 13:58
  • Hmm.. not sure but maybe check this thread stackoverflow.com/questions/33282545/… Commented May 12, 2016 at 14:03
  • 4
    As they specified i have to add /usr/local/share/npm/bin in my PATH Variable. but i don't have any npm directory inside /usr/local/share. Thanks @NaderDabit
    – Ashok R
    Commented May 12, 2016 at 14:12
  • 1
    when i run npm config --global get prefix i can see npm directory in this location -> /usr/local/Cellar/node/6.1.0/libexec/npm. I have added it to PATH variable. Executed react-native init someApp command still same error:-(
    – Ashok R
    Commented May 12, 2016 at 15:42

22 Answers 22

342

After adding right path to the PATH variable issue is resolved.

Below are the steps to find the right path.

1. Enter: npm install -g react-native-cli
output: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native ->/usr/local/Cellar/node/6.1.0/libexec/npm/lib/node_modules/react-native-cli/index.js/usr/local/Cellar/node/6.1.0/libexec/npm/lib
└── [email protected] 

from above output you can clearly see the path: /usr/local/Cellar/node/6.1.0/libexec/npm/bin/react-native

export PATH="/usr/local/Cellar/node/6.1.0/libexec/npm/bin:$PATH"

react-native init appName

cd appName

react-native run-ios

if you getting xcrun: error: unable to find utility "simctl" at this stage you can reslove using below steps

XCode -> Preferences -> Locations -> Command Line Tools -> Choose Xcode 7.2.1

You can find original solution from xcrun unable to find simctl

Thanks to @fbozo

That's It!!!

8
  • No bin folder inside npm!?
    – Eftekhari
    Commented May 7, 2017 at 18:08
  • 1
    Its not solved permanently. But after opening new terminal, same issue is happening. How to fix this permanently? Commented Jun 9, 2017 at 6:07
  • 1
    stackoverflow.com/questions/22465332/… @Balasubramanian
    – Ashok R
    Commented Jun 9, 2017 at 8:48
  • This doesn't work if you aren't using sudo to install your npm modules. See stackoverflow.com/a/49124013/280795 for the fix. Commented Mar 6, 2018 at 5:35
  • 1
    In my case, I had changed my default version of node with NVM, and had forgotten to install react-native again for this new node version. Thank you! Commented Sep 14, 2018 at 19:18
59

run this code

npm i -g react-native-cli

close your cmd and open it again

2
  • 8
    This suggestion did not fix the problem for me.
    – Mike S.
    Commented Mar 29, 2019 at 20:06
  • I followed the instructions and it didn't work. But then I had to run also npm install close open and it worked. Commented Oct 13, 2021 at 13:11
51

Try

npx react-native

if doesn't work install globally

npm i -g react-native-cli
3
  • 4
    npx react-native worked for me, thanks. Commented Aug 11, 2021 at 17:18
  • npm i -g react-native-cli works like a charm, thanks. Commented Jun 30, 2022 at 8:33
  • npx react-native info Commented Jan 25, 2023 at 12:44
48

After continually running into this problem, and hitting this answer and not having it work..

Assuming you don't run npm as root/sudo (which you shouldn't do!) your npm modules will be installed in whatever you set your default directory to be.

Assuming you have followed those instructions, and your default directory is ~/.npm-global, then you need to add ~/.npm-global/bin to your path.

This is outlined in those instructions, but for me I added this to .bashrc:

export PATH=$PATH:$HOME/.npm-global/bin

Then restart your shell and it will work.

1
  • after being tired of trying almost hundreds of solutions this worked charm on my case, my problem actually was when i close terminal and started again then react-native command was not found.
    – TankRaj
    Commented May 17, 2019 at 6:11
25

If who have error , try it with sudo:

sudo npm install -g react-native-cli

17

If you're using yarn, you may have to run commands with yarn in front. Example:

yarn react-native info
0
10

I ran into this issue by being a bit silly. I use nvm to manage my different versions of node, and installed react-native into a version of node that was not my default. Upon opening a new shell, I lost my command. :) Switching back of course fixed things.

1
  • 2
    Or just globally install it again. Soooo, simple. $ npm i -g react-native-cli Commented Sep 19, 2019 at 7:57
9

If for some strange reasons, the path to react-native is not in the PATH, you should take note where the react-native executable is installed. Generally, the issue with command not found is because they are not in PATH.

For example, I use nodenv and run npm install -g react-native

/Users/khoa/.nodenv/versions/10.10.0/bin/react-native -> /Users/khoa/.nodenv/versions/10.10.0/lib/node_modules/react-native/local-cli/wrong-react-native.js

So I need to add that to my PATH

export PATH=$HOME/.nodenv/versions/10.10.0/bin:$PATH

You can verify with echo $PATH

Or you can use npx to execute local npm modules, for example

npx react-native run-ios --simulator='iPhone X'
0
9

Install react-native globally by using the following command

npm i -g react-native-cli
4

Had the same issue but half of your approach didn't work for me . i took the path the way you did :from the output of react-native-cli instal but then manually wrote in ect/pathes with:

sudo nano /etc/paths

at the end i've added the path from output then ctrl x and y to save . Only this way worked but big thanks for the clue!

0
4

Install react-native-cli with npm install -g react-native-cli. You may need to use sudo like sudo npm install -g react-native-cli

3

At first run this command on your terminal.

npm i -g react-native-cli

Then create your react-native project by this command.

React-native init Project name

then move to your project directory by cd command.

2

According to official documentation, the following command worked for me.

  • npx react-native run-android

Link is here

I was trying to run by "react-native run-android" command. make sure to have react-native cli installed globally!

1

In case anyone has this problem, I had a similar problem to qix, but more nuanced.

New shell terminals would default to a different version of node. I would change my terminal to the node I wanted, but when the bundle script run, it ran in a new shell, and it got the default version which did not have react-native installed.

I used nvm alias default x.x.x so that new shells would inherit the default version I wanted.

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install yarn
brew install node
brew install watchman
brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk8
npm install -g react-native-cli
1
  • 2
    why do we need to install this many things to solve a problem so little? e.g: using nuclear weapons on ant colonies.
    – zinoadidi
    Commented Apr 9, 2020 at 6:10
1

Dears,

Please try : npm install -g react-native-cli

If you get an error like Cannot find module ‘npmlog’ you can install npm directly using this command. If the above command run successfully then no need to run this command

curl -0 -L https://npmjs.org/install.sh | sudo sh

#For_Ubuntu.

Best regards.

1

In cmd Administration mode,Run

npm install react-native-cli

1
  • The command you wrote was already used by the person who asked the question, the issue was not related to the command. So please, see the complete discussion related to the solution and ideas for the problem before giving the answer.
    – Not A Bot
    Commented Oct 23, 2020 at 7:58
0

This is really weird, on my side (macOS 10.14), i'm pretty sure my node and npm work but i kept getting command not found only for this particular package. I ended up doing the following:

You can now debug view hierarchy and see console logs in react-native-debugger

0

I already had react-native and react-native-cli installed and just had to run:

yarn install
0

I had this issue after ejecting from expo and forgot to delete the node_modules and reinstall by running yarn or npm install.

After I did that then run npx react-native run-android, it worked fine!

-2

try using react-native --help and see what comes up. try curl

react native library recommendation:

If you get an error like Cannot find module 'npmlog', try installing npm directly: curl -0 -L https://npmjs.org/install.sh | sudo sh.

https://facebook.github.io/react-native/docs/getting-started.html

2
  • the original problem is that 'react-native' command is not found. it is not possible to run react-native --help either
    – zinoadidi
    Commented Apr 9, 2020 at 6:11
  • I ignored the fact that you made a mistake when installing React Native by following the steps in the official Facebook documentation, because I thought you were not a beginner. Now that I'm sure you're a beginner, I can help you better Commented Apr 9, 2020 at 16:33
-2

I did an npm update, runned into the same error but after do an npm install and re-build the app worked!

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Oct 2, 2021 at 21:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.