How to Fix '/bin/sh: 1: node: not found' Error When Running JavaScript in Visual Studio Code with Code Runner (Beginner's Guide)

You’ve just written your first JavaScript (JS) script in Visual Studio Code (VS Code), installed the popular Code Runner extension to run it, and clicked "Run Code"—only to be greeted by a frustrating error: /bin/sh: 1: node: not found. If you’re new to coding, this error might seem intimidating, but fear not! It’s one of the most common issues beginners face when setting up their JS development environment, and it’s easy to fix once you understand the root cause.

In this guide, we’ll break down why this error occurs, walk you through step-by-step solutions to resolve it, and ensure you can run your JS code smoothly in VS Code with Code Runner. No prior technical expertise is required—we’ll explain everything in simple terms!

Table of Contents#

  1. What Causes the '/bin/sh: 1: node: not found' Error?
  2. Prerequisites
  3. Step-by-Step Solutions
  4. Verify the Fix
  5. Troubleshooting Common Issues
  6. Conclusion
  7. References

What Causes the '/bin/sh: 1: node: not found' Error?#

Before diving into fixes, let’s understand the error. The message /bin/sh: 1: node: not found is your computer’s way of saying: "I tried to run the 'node' command, but I can’t find it anywhere."

Here’s why this happens:

  • Node.js is not installed: Code Runner uses Node.js (a JavaScript runtime) to execute JS files. If Node.js isn’t installed on your system, the node command won’t exist.
  • Node.js is installed, but not in your system’s PATH: Even if Node.js is installed, your operating system (OS) might not know where to find the node executable. The "PATH" is a system variable that tells your OS which folders to search for executable programs (like node). If Node.js isn’t in the PATH, the OS can’t "see" it.

Prerequisites#

Before starting, ensure you have:

  • Visual Studio Code installed: Download it from code.visualstudio.com.
  • Code Runner extension installed: In VS Code, go to the Extensions tab (Ctrl+Shift+X or Cmd+Shift+X), search for "Code Runner", and install it.
  • A simple JavaScript file to test (e.g., test.js with console.log("Hello, World!");).

Step-by-Step Solutions#

Step 1: Check if Node.js is Already Installed#

First, confirm whether Node.js is installed.

  1. Open the VS Code terminal:

    • On Windows: Press Ctrl+` (backtick) or go to Terminal > New Terminal.
    • On macOS/Linux: Press Cmd+` or go to Terminal > New Terminal.
  2. In the terminal, run:

    node -v  

    or

    node --version  
    • If Node.js is installed, you’ll see a version number (e.g., v20.10.0). Skip to Step 4.
    • If you see an error (e.g., command not found: node or /bin/sh: 1: node: not found), Node.js is not installed. Proceed to install it.

Step 2: Install Node.js (If Not Installed)#

Node.js is free and easy to install. Follow these steps for your OS:

For Windows#

  1. Go to the official Node.js website.
  2. You’ll see two versions: LTS (Long Term Support) (recommended for most users) and Current (latest features). Click the "LTS" button to download the installer (e.g., node-v20.10.0-x64.msi).
  3. Run the installer. When prompted, check the box: "Add to PATH" (critical for Step 4!).
  4. Follow the installer prompts (click "Next" until finished).

For macOS#

  1. Go to nodejs.org and download the LTS installer for macOS (e.g., node-v20.10.0.pkg).
  2. Run the installer and follow the prompts. macOS will automatically add Node.js to your PATH in most cases.

For Linux (Ubuntu/Debian)#

Option 1: Use the NodeSource PPA (recommended for latest LTS):

  1. Open the VS Code terminal and run:
    curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -  
    sudo apt install -y nodejs  

Option 2: Use the default package manager (may have older versions):

sudo apt update  
sudo apt install nodejs npm  

Step 3: Verify Node.js Installation#

After installation, confirm Node.js works:

  1. Close and reopen the VS Code terminal (to refresh PATH settings).

  2. Run:

    node -v  

    You should see a version number (e.g., v20.10.0). If not, Node.js wasn’t installed correctly—reinstall using the steps above.

Step 4: Ensure Node.js is in Your System’s PATH#

If node -v works in the terminal but Code Runner still throws the error, Node.js might not be in your system’s PATH. Here’s how to fix it:

Check Your PATH#

First, check if Node.js is in your PATH:

  • Windows: In the VS Code terminal (PowerShell or Command Prompt), run:

    echo %PATH%  

    Look for a folder like C:\Program Files\nodejs\ (the default Node.js install path).

  • macOS/Linux: In the terminal, run:

    echo $PATH  

    Look for /usr/local/bin or /usr/bin (common Node.js paths).

Add Node.js to PATH (If Missing)#

Windows#
  1. Open "System Properties":
    • Press Win + R, type sysdm.cpl, and hit Enter.
    • Go to the "Advanced" tab > "Environment Variables".
  2. Under "System Variables", find the "Path" variable and click "Edit".
  3. Click "New" and add the path to your Node.js folder (e.g., C:\Program Files\nodejs\).
  4. Click "OK" to save. Close and reopen VS Code.
macOS/Linux#
  1. Open your shell configuration file (e.g., .bashrc, .zshrc, or .profile). For most users, this is ~/.bashrc or ~/.zshrc:
    nano ~/.bashrc  # or ~/.zshrc  
  2. Add this line at the bottom (replace /path/to/nodejs with your Node.js install path; default is usually /usr/local/bin):
    export PATH="$PATH:/path/to/nodejs"  
    For example, if Node.js is in /usr/local/bin, the line is redundant (since /usr/local/bin is already in PATH), but if it’s in ~/nodejs/bin, use:
    export PATH="$PATH:~/nodejs/bin"  
  3. Save the file (Ctrl+O, Enter, then Ctrl+X in nano).
  4. Refresh your terminal:
    source ~/.bashrc  # or source ~/.zshrc  

Step 5: Configure Code Runner (Optional)#

Code Runner uses a "executor map" to decide how to run files. By default, it uses node for JS files, but you can explicitly set the path to Node.js if needed.

  1. Open VS Code settings:

    • Press Ctrl+, (Windows/Linux) or Cmd+, (macOS) to open Settings.
    • Search for "Code Runner: Executor Map" and click "Edit in settings.json".
  2. Ensure the javascript entry uses the correct node command. The default is:

    "code-runner.executorMap": {  
      "javascript": "node"  
    }  

    If Node.js is installed in a non-default path (e.g., C:\Tools\nodejs\node.exe on Windows), replace "node" with the full path:

    "javascript": "C:\\Tools\\nodejs\\node"  # Windows  
    "javascript": "/usr/local/bin/node"      # macOS/Linux  
  3. Save settings.json and restart VS Code.

Verify the Fix#

Now, test if the error is resolved:

  1. Open your test JS file (e.g., test.js) in VS Code.
  2. Right-click in the editor and select "Run Code", or use the Code Runner shortcut (Ctrl+Alt+N or Cmd+Alt+N).

If successful, you’ll see:

Hello, World!  

in the VS Code "Output" tab.

If the error persists, revisit Steps 3–4 to ensure Node.js is installed and in your PATH.

Troubleshooting Common Issues#

"node -v" works in terminal but not in Code Runner#

  • Restart VS Code: VS Code may not pick up PATH changes until restarted.
  • Use VS Code’s integrated terminal: Code Runner uses the same terminal environment as VS Code. If node -v works in the integrated terminal but not in Code Runner, restart VS Code.

Permission errors on Linux/macOS#

If you see EACCES: permission denied when installing Node.js, use sudo (e.g., sudo apt install nodejs) or install Node.js via nvm (Node Version Manager) to avoid permission issues.

Multiple Node.js versions installed#

If you have multiple Node.js versions (common with tools like nvm), ensure the correct version is active:

nvm use 20  # Replace "20" with your LTS version  

Antivirus blocking Node.js#

Some antivirus tools flag Node.js as suspicious. Temporarily disable your antivirus during installation, then re-enable it.

Conclusion#

The /bin/sh: 1: node: not found error is a common roadblock for beginners, but it’s easily fixed by installing Node.js and ensuring it’s in your system’s PATH. By following this guide, you’ve learned how to:

  • Check for Node.js installation,
  • Install Node.js on Windows, macOS, or Linux,
  • Verify Node.js is in your PATH,
  • Configure Code Runner (if needed),
  • Troubleshoot common issues.

Now you’re ready to run JavaScript files in VS Code with Code Runner seamlessly!

References#