-bash: react-native: command not found
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 + [email protected] 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!
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
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"