node.js -bash: react-native: 命令未找到
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33282545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
-bash: react-native: command not found
提问by loungeonbench
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:
我已经成功安装了 brew、node 4.0+、watchman 和 flow,我在安装时收到以下信息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-clihas been successfully installed as well. However when I run react-native, it says:
所以我假设react-native-cli也已成功安装。但是,当我运行时react-native,它说:
-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
我的节点版本是 4.2.1,watchman 3.9,brew 0.9.5 (git 7ed6) 和 npm 2.14.7
回答by bfontaine
You have to make sure /usr/local/share/npm/binis in your PATHto use binaries installed with npm.
您必须确保/usr/local/share/npm/bin在您PATH使用的二进制文件中安装了npm.
Add the following to your ~/.bashrc:
将以下内容添加到您的~/.bashrc:
export PATH="/usr/local/share/npm/bin:$PATH"
And reload your shell session.
并重新加载您的 shell 会话。
If you find you don't have a /usr/local/share/npm/bindirectory, your npmmay install its packages in another location. In this case you have to use the right path in the line above.
如果你发现你没有/usr/local/share/npm/bin目录,你npm可以在另一个位置安装它的包。在这种情况下,您必须使用上一行中的正确路径。
One solution to find that path is to run:
找到该路径的一种解决方案是运行:
npm list -g | head -n 1
This gives you the path where npminstall 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 libwith binto get the correct path:
这为您提供了npm安装其软件包的路径。这不是你想要的路径,但它很接近。例如在我的 Linux 上,它给出了/home/baptiste/.linuxbrew/lib; 只需替换libwithbin即可获得正确的路径:
export PATH="/home/baptiste/.linuxbrew/bin:$PATH"
回答by 0xa6a
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:
我尝试了很多方法来在我的 mac( node -v: v8.1.3, npm -v: 5.0.3)上找到解决方案。当我运行时npm install -g react-native-cli,输出是这样的:
/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
/Users/xxx/.npm-packages/bin/react-native -> /Users/xxx/.npm-packages/lib/node_modules/react-native-cli/index.js + [email protected]在 2.988 秒内更新了 1 个包
As you can see react-nativewas 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:$PATHto my ~/.profileand opened a new Terminal window to run react-native. It worked!
如您所见react-native,安装在 中/Users/xxx/.npm-packages/bin/,与其他人可能说的不同。所以我将该行粘贴export PATH=/Users/xxx/.npm-packages/bin:$PATH到 my~/.profile并打开一个新的终端窗口来运行react-native. 有效!
回答by Azhar
First of all, you have to install react native globally
首先,你必须全局安装react native
npm install -g react-native-cli
then it will show you the path for the react native like the following
然后它会向您显示 react native 的路径,如下所示
/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
谢谢
回答by Mohammed Fallah
It's easy!
这很简单!
Just run npm i -g react-native-clithen restart your cmd.
只需运行npm i -g react-native-cli然后重新启动您的cmd。
回答by Siya
export PATH="$HOME/.npm-packages/bin:$PATH" worked for me however, I had to replace packages with what was on my mac.
export PATH="$HOME/.npm- packages/bin:$PATH" 对我有用,但是,我不得不用我的 mac 上的包替换包。
i.e .npm-globalinstead of .npm-packages. ..
即 .npm-global而不是 .npm- packages。..
回答by Rajesh Nasit
Step 1 .
第1步 。
terminal fire : npm install -g react-native-clioutput: /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]
终端火:npm install -g react-native-cli输出:/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]
回答by Rajesh Nasit
Step 1 .
第1步 。
terminal fire : npm install -g react-native-cli
终端火灾: 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
+ [email protected]
updated 1 package in 4.544s
Step 2: export the path
第二步:导出路径
export PATH="/usr/local/Cellar/node/13.3.0/bin:$PATH"
回答by u6937338
sudo npm install -g react-native-cli

