26

I have successfully installed brew, node 4.0+, watchman and flow, and I received the following when I do npm install -g react-native-cli:

/Users/home/.node/bin/react-native -> /Users/home/.node/lib/node_modules/react-native-cli/index.js
react-native-cli@0.1.5 /Users/home/.node/lib/node_modules/react-native-cli
           └── prompt@0.2.14 (revalidator@0.1.8, pkginfo@0.3.1, read@1.0.7, winston@0.8.3, utile@0.2.1)

So I assume react-native-cli has been successfully installed as well. However when I run react-native, it says:

-bash: react-native: command not found

My node version is 4.2.1, watchman 3.9, brew 0.9.5 (git 7ed6) and npm 2.14.7

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
loungeonbench
  • 263
  • 1
  • 3
  • 4
  • ***react-native: command not found.*** http://stackoverflow.com/questions/37189081/react-native-command-not-found – Ashok R Dec 05 '16 at 06:10
  • Others using `nvm` may want to check that their `nvm` version is sustaining. I had this issue when I had old `npm` bin routes in my `PATH` that needed to be removed – bananabanana Feb 21 '19 at 17:17
  • This worked for me, maybe this may be the solution for a similar issue. https://github.com/facebook/react-native/issues/24594#issuecomment-486894348 – AhkyHabibah May 28 '19 at 17:59

8 Answers8

37

You have to make sure /usr/local/share/npm/bin is in your PATH to use binaries installed with npm.

Add the following to your ~/.bashrc:

export PATH="/usr/local/share/npm/bin:$PATH"

And reload your shell session.


If you find you don’t have a /usr/local/share/npm/bin directory, your npm may install its packages in another location. In this case you have to use the right path in the line above.

One solution to find that path is to run:

npm list -g | head -n 1

This gives you the path where npm install its packages. This is not the path you want but it’s close. For example on my Linux it gives /home/baptiste/.linuxbrew/lib; it suffices to replace lib with bin to get the correct path:

export PATH="/home/baptiste/.linuxbrew/bin:$PATH"

You can use $HOME to get your own home directory:

export PATH="$HOME/.linuxbrew/bin:$PATH"
bfontaine
  • 18,169
  • 13
  • 73
  • 107
21

I tried many ways to work out a solution to this on my mac(node -v: v8.1.3, npm -v: 5.0.3). And when I ran npm install -g react-native-cli, the output was this:

/Users/xxx/.npm-packages/bin/react-native -> /Users/xxx/.npm-packages/lib/node_modules/react-native-cli/index.js + react-native-cli@2.0.1 updated 1 package in 2.988s

As you can see react-native was install in /Users/xxx/.npm-packages/bin/, different from what others may say. So I pasted the line export PATH=/Users/xxx/.npm-packages/bin:$PATH to my ~/.profile and opened a new Terminal window to run react-native. It worked!

wzso
  • 3,482
  • 5
  • 27
  • 48
11

First of all, you have to install react native globally

npm install -g react-native-cli

then it will show you the path for the react native like the following

/Users/{yourUser}/.npm-packages/bin/react-native -> /Users/{yourUser}/.npm-packages/lib/node_modules/react-native-cli/index.js

Then you have to set the default path from the above result and execute the following command

export PATH="/Users/{yourUser}/.npm-packages/bin/:$PATH"

or

export PATH="$HOME/.npm-packages/bin:$PATH"

Then reload you session/env vairables

source ~/.bash_profile

It works for me .... cheers

thanks

Azhar
  • 20,500
  • 38
  • 146
  • 211
  • If you are getting Error: EACCES: permission denied, access '/usr/local/lib/node_modules' issue then try sudo npm install -g react-native-cli to install the packages – Rama Apr 08 '20 at 00:23
2

Step 1 .

terminal fire : npm install -g react-native-cli

output: 

/usr/local/Cellar/node/13.3.0/bin/react-native -> /usr/local/Cellar/node/13.3.0/lib/node_modules/react-native-cli/index.js
+ react-native-cli@2.0.1
updated 1 package in 4.544s

Step 2: export the path

  export PATH="/usr/local/Cellar/node/13.3.0/bin:$PATH"
Rajesh N
  • 6,198
  • 2
  • 47
  • 58
0

It's easy!

Just run npm i -g react-native-cli then restart your cmd.

noetix
  • 4,773
  • 3
  • 26
  • 47
Mohammed Fallah
  • 759
  • 6
  • 9
0

export PATH="$HOME/.npm-packages/bin:$PATH" worked for me however, I had to replace packages with what was on my mac.

i.e .npm-global instead of .npm-packages. ..

Siya
  • 1
0

Step 1 .

terminal fire : 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 └── react-native-cli@0.2.0

Rajesh N
  • 6,198
  • 2
  • 47
  • 58
-4
sudo npm install -g react-native-cli
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
  • 1
    this and is half right , though you can have a look at correct one ,it also includes env export https://stackoverflow.com/a/48638712/1390678 – vijay Jun 06 '18 at 08:32