How to fix npm live-server: command not found error

The npm live-server package is used to create a local server to help you develop applications.

Sometimes, the error live-server command not found error may appear after you’ve installed it as follows:

$ live-server
bash: live-server: command not found 

This error happens because your computer can’t find the globally installed live-server package.

First, make sure that you are installing the package using the --global flag:

npm install --global live-server
# or
npm install -g live-server

Once installed, you need to check for the global installation path of your npm packages using the npm bin -g command.

Here’s an example output of the command:

$ npm bin -g

# 👇 example output on Windows

# 👇 example output on Mac or Linux

The global install path you get with the npm bin -g command needs to be available from the PATH environment variable of your computer.

To update the PATH on a Windows computer, you need to follow the steps below:

  • Open the Start menu and type env in the search bar.
  • A menu named Edit the system environment variables should show up. Click on the menu
  • Click on Environment Variables… button
  • Open the Path variable and see if the npm bin -g path is added as an entry

You should see something similar to this:

Save the changes by clicking the OK button, then open a new command line or Git Bash window.

You should be able to run live-server successfully now.

On Mac or Linux computers, you need to add the bin location to the .zshrc or .bashrc file depending on the terminal you use on the computer.

The RC files should be available in the user’s root directory of the user when you open the terminal.

You can move to your root directory by running the cd ~ command.

Add an EXPORT PATH variable in the RC file as follows:

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

Replace /usr/local/bin above with your npm bin -g output. Also, make sure there is a colon : before the $PATH variable as shown above.

That should help you to run the live-server package on Mac and Linux computers.

If you’re installing Node using NVM, then you need to make sure the following entries are defined in your RC files

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"  # This loads nvm

The NVM_DIR variable must point to an existing nvm folder.

For Windows, you need to check the Path variables and make sure there are %NVM_HOME% and %NVM_SYMLINK% variables added:

If you don’t see the variables as shown above, try to add them manually and open a new command line window.

When that doesn’t work, then try reinstalling NVM for Windows.

And that’s how you fix the live-server command not found error. 👍

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.