You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

zsh下npm全局安装live-server后命令找不到的问题求助

Fixing "zsh: command not found: live-server" with Oh My Zsh

Let's break down what's going on here and fix it step by step:

The Root Cause

First, notice the critical mismatch in your paths:

  • Your live-server is installed at /Users/username/.npm-global/lib/node_modules/live-server (note the dot before npm-global)
  • But in your $PATH and .zshrc config, you're adding /Users/username/npm-global/bin and /Users/username/npm-global/lib (missing that leading dot)

npm links global command-line tools like live-server to the bin directory inside your global npm folder (~/.npm-global/bin). Since your PATH doesn't include the correct directory with the dot, zsh can't locate the live-server executable.

Step-by-Step Fix

1. Correct the PATH in your .zshrc

Open your .zshrc file in your preferred editor (e.g., vim ~/.zshrc or nano ~/.zshrc), then find these lines at the bottom:

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

Replace them with the correct paths (add the dot before npm-global), and clean up unnecessary entries:

export PATH=$PATH:/Users/username/.npm-global/bin
# The lib directory holds node modules, not executable commands—you can safely delete the second export line

2. Reload your .zshrc configuration

To make the changes take effect immediately without restarting your terminal, run:

source ~/.zshrc

3. Verify the fix

First, confirm the correct path is now in your $PATH:

echo $PATH

You should see /Users/username/.npm-global/bin listed. Then test running live-server—it should launch successfully now!

Optional: Double-check npm's global config

If you still hit issues, confirm your npm global directory is set correctly:

npm config get prefix

It should return /Users/username/.npm-global. If it doesn't, set it with:

npm config set prefix '/Users/username/.npm-global'

Then reinstall live-server to ensure proper link setup:

npm install -g live-server

内容的提问来源于stack exchange,提问作者Jon_B

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:00:51