bash NPM 实时服务器:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35527301/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:16:19  来源:igfitidea点击:

NPM live-server: command not found

node.jsbashnpmnpm-liveserver

提问by Timidfriendly

I install live-server globally with:

我在全球范围内安装实时服务器:

npm install -g live-serverbut for some reason it is not be found and I get the following error

npm install -g live-server但由于某种原因找不到它,我收到以下错误

bash: live-server: command not foundafter command live-server

bash: live-server: command not found命令后 live-server

Everything is correctly installed:

一切都已正确安装:

/Users/username/npm-global/bin/live-server ->
/Users/username/npm-global/lib/node_modules/live-server/live-server.js
[email protected] /Users/username/npm-global/lib/node_modules/live-server
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

What am I missing here?

我在这里错过了什么?

回答by bolav

Add the path to your npm installation to your path. Just add this line at the end of .bash_profile. Run it in bash first, to make sure it works before putting it in .bash_profile

将您的 npm 安装路径添加到您的路径中。只需在.bash_profile. 首先在 bash 中运行它,以确保它在放入之前可以正常工作.bash_profile

export PATH=$PATH:/Users/username/npm-global/bin

回答by Ashley Fernandes

The main problem is that node js does not know the path of the installed modules ..

主要问题是节点js不知道安装模块的路径..

Type this command to get the path of all the global modules.

键入此命令以获取所有全局模块的路径。

npm bin -g

It will display the path (C:\Users\gf\AppData\Roaming\npm) and also show (not in PATH env variable)

它将显示路径 (C:\Users\gf\AppData\Roaming\npm) 并显示(不在 PATH 环境变量中)

Copy the path and add it to the path variable of your computer (just like you do while installing other software) for eg : In Windows 7 - Right click on my computer ->select properties -> select advanced system settings -> environment variables

复制路径并将其添加到您计算机的路径变量中(就像您在安装其他软件时所做的那样)例如:在 Windows 7 中 - 右键单击​​我的计算机 -> 选择属性 -> 选择高级系统设置 -> 环境变量

enter image description here

在此处输入图片说明

Double click on the Path variable

双击路径变量

enter image description here

在此处输入图片说明

In the variable value first type a semicolon and paste the path which you copied and that's it every thing should work now..

在变量值中首先输入一个分号并粘贴您复制的路径,就是这样,现在一切都应该可以工作了..

回答by Chris Adams

Just a note, don't just blindly copy and paste the path /Users/username be sure you do the

请注意,不要只是盲目地复制和粘贴路径 /Users/username 确保您执行

npm bin -g

as explained by others and get that actual path into export PATH=$PATH:/YourActualPathHERE

正如其他人所解释的那样,并进入实际路径 export PATH=$PATH:/YourActualPathHERE

回答by Lukasz Stelmach

In my case (Ubuntu with npm installed from package) live-servermodule was not installed. It helps:

在我的情况下(从包安装了 npm 的 Ubuntu)live-server模块没有安装。它有助于:

npm install -g live-server

回答by Sanjay Magar

try to install as root/Administrator

尝试以 root/管理员身份安装

sudo npm install -g live-server

Hope this will solve your problem.. its works for me...

希望这能解决你的问题......它对我有用......