-bash: react-native: 命令未找到 [英] -bash: react-native: command not found

查看:54
本文介绍了-bash: react-native: 命令未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功安装了 brew、node 4.0+、watchman 和 flow,我在执行 npm install -g react-native-cli 时收到以下内容:

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)

所以我假设 react-native-cli 也已成功安装.但是,当我运行 react-native 时,它说:

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

我的 node 版本是 4.2.1,watchman 3.9,brew 0.9.5 (git 7ed6) 和 npm 2.14.7

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

推荐答案

你必须确保 /usr/local/share/npm/bin 在你的 PATH 中使用通过 npm 安装的二进制文件.

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

将以下内容添加到您的~/.bashrc:

Add the following to your ~/.bashrc:

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

并重新加载您的 shell 会话.

And reload your shell session.

如果你发现你没有 /usr/local/share/npm/bin 目录,你的 npm 可能会在另一个位置安装它的包.在这种情况下,您必须使用上一行中的正确路径.

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

这为您提供了 npm 安装其软件包的路径.这不是你想要的路径,但它很接近.例如在我的 Linux 上它给出 /home/baptiste/.linuxbrew/lib;将 lib 替换为 bin 即可获得正确的路径:

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"

您可以使用 $HOME 来获取您自己的主目录:

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

export PATH="$HOME/.linuxbrew/bin:$PATH"

这篇关于-bash: react-native: 命令未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆