14

I install live-server globally with:

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

bash: live-server: command not found after command 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
live-server@0.9.2 /Users/username/npm-global/lib/node_modules/live-server
├── object-assign@4.0.1
├── colors@1.1.2
├── event-stream@3.3.2 (pause-stream@0.0.11, duplexer@0.1.1, stream-combiner@0.0.4, from@0.1.3, map-stream@0.1.0, split@0.3.3, through@2.3.8)
├── opn@4.0.0 (pinkie-promise@2.0.0)
├── send@0.13.1 (escape-html@1.0.3, destroy@1.0.4, statuses@1.2.1, etag@1.7.0, fresh@0.3.0, range-parser@1.0.3, ms@0.7.1, debug@2.2.0, depd@1.1.0, mime@1.3.4, on-finished@2.3.0, http-errors@1.3.1)
├── morgan@1.7.0 (on-headers@1.0.1, basic-auth@1.0.3, depd@1.1.0, on-finished@2.3.0, debug@2.2.0)
├── connect@3.4.1 (utils-merge@1.0.0, parseurl@1.3.1, debug@2.2.0, finalhandler@0.4.1)
├── faye-websocket@0.10.0 (websocket-driver@0.6.4)
├── watchr@2.3.10 (bal-util@1.18.0)
└── serve-index@1.7.3 (parseurl@1.3.1, escape-html@1.0.3, batch@0.5.3, http-errors@1.3.1, debug@2.2.0, mime-types@2.1.10, accepts@1.2.13)

What am I missing here?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Timidfriendly
  • 3,224
  • 4
  • 27
  • 36
  • Possible duplicate of [BrowserSync : Command not found after installing browser-sync](http://stackoverflow.com/questions/35500178/browsersync-command-not-found-after-installing-browser-sync) – bolav Feb 20 '16 at 19:05
  • What does `npm bin -g` return? What does `echo $PATH` return? – bolav Feb 20 '16 at 19:06
  • `npm bin -g` returns `/Users/davidknowles/npm-global/bin` `(not in PATH env variable)` – Timidfriendly Feb 20 '16 at 19:11
  • Add `/Users/davidknowles/npm-global/bin` to your path, as I said in my answer. `npm` is probably installed to another directory. (See which by running `which npm`.) – bolav Feb 20 '16 at 19:12
  • `echo $PATH` returns `/usr/local/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin` – Timidfriendly Feb 20 '16 at 19:13
  • `npm bin -g` solved it for me That let me know my path with: `/Users/MYUSERNAMEHERE/.npm-packages/bin` (not in PATH variable) I opened .zshrc and added this line: `export PATH=$PATH:/Users/MYUSERNAMEHERE/.npm-packages/bin` Refresh your .zshrc and live-reload works I am obviously using zsh but you could apply this to bash as well I think problems arise when people install using brew versus manually and that is why the solutions vary with regard to paths as manually and homebrew install to different directories – Pip Dec 11 '17 at 16:45

9 Answers9

14

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

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)

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

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..

Ashley Fernandes
  • 1,179
  • 10
  • 18
13

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

export PATH=$PATH:/Users/username/npm-global/bin
bolav
  • 6,938
  • 2
  • 18
  • 42
7

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

npm install -g live-server
Lukasz Stelmach
  • 5,281
  • 4
  • 25
  • 29
7

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

npm bin -g

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

Christopher Adams
  • 1,240
  • 10
  • 14
  • Will I need to do this every time I reset my computer if I don't add that to my .bash_profile ? – teewuane Apr 19 '20 at 21:26
  • Answering my own question, the answer is yes, yes you do unless you add to your .bash_profile or .zshrc . – teewuane Apr 20 '20 at 01:43
6

try to install as root/Administrator

sudo npm install -g live-server

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

Sanjay Magar
  • 121
  • 2
  • 2
1

If you on windows 10.

Assuming Nodejs is installed, npm is installed, GitBash terminal is installed

1.Install Linux subsystem for windows: Open PowerShell and type:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

  1. Open gitBash.exe terminal and type: $ npm bin -g

  2. Copy the Path: C:\Users\YourMachineName\AppData\Roaming\npm

5.Click the search icon and type Environment...

6.Choose Edit environment variables for your account

enter image description here

enter image description here

enter image description here

  1. Go back to Your code Editor, or another terminal and test the work.
  2. There is a probability that Powershell will not work. That is why you should select GitBash as your default terminal if you develop a website using VSCode on Windows. enter image description here
Dmitry
  • 177
  • 1
  • 6
0

Update to http-server. You can install globally using

npm install --global http-server

You can find the docs at https://www.npmjs.com/package/http-server

WhooNo
  • 911
  • 2
  • 12
  • 28
0

Just try to use live-server in your project as a dev-dependency. Yes, it is not the recommended way. But it is a shortcut and will save your precious time.

0

My npm live-server works well until it suddenly stopped without any error. I then must change to use live-server of Visual Studio code instead. After read many article i found that my path variable missing C:\Windows\System32\ variable. Check carefully your path environment variable to make sure you have all the addresses needed.

Tuan Luu
  • 69
  • 5