‘npm’ is not recognized as internal or external command, operable program or batch file

In this tutorial, I will show you how to fix the issue ‘npm’ is not recognized as internal or external command, operable program, or batch file in Node.js.

The error “‘npm’ is not recognized as an internal or external command, operable program or batch file” typically occurs when the Node Package Manager (npm) executable is not in the system’s PATH. To fix this issue, you need to add the directory containing npm to your system’s PATH environment variable.

Here’s a step-by-step tutorial to help you resolve this issue:

For Windows

Locate npm Path:

    Find where Node.js is installed on your system. The npm executable is usually in the node_modules folder within the Node.js installation directory.

    Copy npm Path:

    Copy the path to the npm executable. It should look something like this:

    C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js

    Set Environment Variable:

    • Right-click on “This PC” or “Computer” on your desktop or in File Explorer and select “Properties.”
    • Click on “Advanced system settings” on the left.
    • Click the “Environment Variables” button.
    • In the “System variables” section, select the “Path” variable and click “Edit.”
    • Click “New” and paste the path you copied in step 2.
    • Click “OK” to close each dialog box.

    Restart Your Command Prompt:

    • Close and reopen your command prompt or open a new one.

    Verify Installation:

    • Type npm -v and press Enter. You should see the npm version number, indicating that npm is now recognized.

    For macOS/Linux

    Locate npm Path:

    Open a terminal and find where Node.js is installed. The npm executable is usually in the bin folder within the Node.js installation directory.

    Copy npm Path:

    Copy the path to the npm executable. It should look something like this:

    /usr/local/bin/npm

    Set Environment Variable:

    Open the .bashrc or .bash_profile file in your home directory using a text editor. For example:
    nano ~/.bashrc

    Add the following line at the end of the file:

    export PATH=/path/to/npm/directory:$PATH

    Save the file and exit the text editor.

    Apply Changes:

    In the terminal, type source ~/.bashrc or source ~/.bash_profile to apply the changes immediately.

    Verify Installation:

    Type npm -v and press Enter. You should see the npm version number, indicating that npm is now recognized.

    Now, npm should be recognized as a command in your terminal or command prompt. This should resolve the issue you were facing.

    Leave a Comment

    Your email address will not be published. Required fields are marked *

    Scroll to Top