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

Laravel 5.6执行npm install报错:npm不是内部或外部命令

Fixing "npm is not an internal or external command" in Laravel 5.6

Hey there, let's get that annoying npm error sorted out quickly. That message pops up because your system can't find the npm command—usually because Node.js isn't installed, or it's not properly added to your system's environment variables. Here's how to fix it step by step:

1. Check if Node.js & npm are installed

First, let's confirm whether Node.js and npm are even on your system. Open up your terminal (Command Prompt on Windows, Terminal app on Mac/Linux) and run these two commands:

node -v
npm -v

If either command throws an error or doesn't show a version number, you need to install Node.js. Grab the LTS (Long-Term Support) version from the official Node.js site—it's the most stable choice for Laravel projects. When installing, make sure to check the box that says "Add to PATH" (this automatically configures your system to recognize node and npm commands everywhere).

2. Fix environment variables if Node.js is already installed

If you already have Node.js installed but still see the error, the problem is likely that your system's PATH doesn't include the Node.js directory.

  • Windows: Right-click "This PC" → "Properties" → "Advanced System Settings" → "Environment Variables". Under "System Variables", find the Path entry, click "Edit", and add the path to your Node.js installation folder (usually C:\Program Files\nodejs\). Save your changes, then restart your Command Prompt.
  • Mac/Linux: Open your terminal and check if the Node.js path is in your shell config file (like ~/.bashrc or ~/.zshrc). If not, add this line (replace the path with your actual Node.js install location):
    export PATH="/usr/local/bin/node:$PATH"
    
    Save the file, then run source ~/.bashrc (or source ~/.zshrc) to apply the changes, or just restart your terminal.

3. Verify your Laravel project's package.json

While your composer.json looks fine, Laravel relies on a package.json file to manage frontend dependencies. If this file is missing from your project root, run:

npm init

Follow the prompts to generate a new package.json, or you can copy the default package.json content from a fresh Laravel 5.6 project (it should include dependencies like laravel-mix, vue, etc.).

Quick extra tip

After installing Node.js, it's a good idea to update npm to the latest version:

npm install -g npm

Once you've done these steps, go back to your Laravel project root and run npm install again—it should work without that error now!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:19:28