Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

The http-server command does not run after installing it

Errorhttp-server: command not found

Short answer

http-server is a command-line package, so it must be installed globally or run through npx. If it is installed but not found, npm's global bin folder is missing from your PATH. Run npx http-server, or add the folder printed by npm prefix -g (plus bin on Linux and macOS) to PATH.

  • Applies to Node.js 22, npm 10, Linux, macOS
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether npm installed it globally and where npm puts executables.

    npm ls -g --depth=0
    npm prefix -g
  2. 2Match what you see, then jump to its fix

    1. 1npm ls -g does not list http-serverIt was installed locally, not globallyFix
    2. 2npm ls -g lists http-server but the shell still cannot find itnpm's global bin folder is not on PATHFix
    3. 3npm install -g stopped with EACCES, so no command was createdThe global install failed with a permission errorFix

What does the error look like?

  • http-server: command not found

Cause 1 of 3

It was installed locally, not globally

1Check

A plain npm install http-server puts the package in node_modules of the current folder and does not create a command in your shell.

npm ls -g --depth=0 | grep http-server || echo 'not installed globally'

2Fix

Install it globally, or skip the install and run it on demand with npx. Serving the current folder needs no other option.

npm install --global http-server
# or, without installing:
npx http-server

3Verify

Start it and open http://localhost:8080, the default port.

http-server

Confirmed by github.com

Did this fix it?

Cause 2 of 3

npm's global bin folder is not on PATH

1Check

Global executables are linked into {prefix}/bin on Unix and straight into the prefix on Windows (%AppData%\npm by default). That folder has to be on PATH.

echo "$PATH"
ls "$(npm prefix -g)/bin"

2Fix

Add the folder to PATH in your shell profile, then open a new terminal.

# ~/.profile or ~/.zshrc (Linux and macOS)
export PATH="$(npm prefix -g)/bin:$PATH"

3Verify

In a new terminal, ask the shell where the command is.

command -v http-server

Confirmed by docs.npmjs.com

Did this fix it?

Cause 3 of 3

The global install failed with a permission error

1Check

The default prefix is often a system folder such as /usr/local. npm's own guide recommends a Node version manager to avoid this; the alternative is a prefix in your home folder.

npm prefix -g

2Fix

Point the prefix at a folder you own and put its bin on PATH (not for Windows), then install again without sudo.

npm config set prefix ~/.local
echo 'PATH=~/.local/bin:$PATH' >> ~/.profile
source ~/.profile
npm install --global http-server

3Verify

Run the command from any folder.

http-server --help

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Use npx for one-off tools you do not need on every project.
  • Install Node.js with a version manager so global installs never need sudo.
  • After changing PATH, open a new terminal before testing.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

npm install worked but the command is not found

bash: vite: command not found

npm puts a local install's command in the project's node_modules/.bin, which is not on your shell PATH, so run it with npx or from an npm script.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.