Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

node.js - -bash: react-native: command not found

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
[email protected] /Users/home/.node/lib/node_modules/react-native-cli
           └── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...