Fixing "Bash: node: command not found" when running a shell script

Abstract: Resolve the Bash node command not found error by adding the Node.js binary path to the system PATH environment variable.

Created: 2026-08-02 by
The "Bash: node: command not found" error occurs because the shell cannot locate the Node.js executable in your system's PATH environment variable. This typically happens when Node is installed via a version manager like nvm, or when the installation directory was not added to your profile configuration files such as .bashrc or .profile.

Understanding the Root Cause

When you execute a command in Bash, the shell searches through directories listed in the PATH environment variable to find the corresponding executable file. If Node.js is installed but its binary location (usually /usr/local/bin/node, ~/.nvm/versions/node/vX.X.X/bin/node, or similar) is missing from this list, Bash throws the command not found error. This issue is distinct from syntax errors or missing dependencies; it is purely a path resolution problem. Common scenarios include installing Node.js globally without updating shell configurations, using a package manager that isolates binaries, or running scripts in an environment where environment variables are not inherited correctly.

Verifying Node.js Installation

Before modifying paths, confirm that Node.js is actually installed on your system. Open your terminal and run the following command:
which node
If this returns a path, note it down. If it returns nothing, Node.js might not be installed, or it is installed in a non-standard location. You can also check the version to ensure it is functional:
node --version
If this command fails with the same command not found error, proceed to the next step to manually locate the binary. On Linux and macOS, you can search for the binary using:
find / -name "node" -type f 2>/dev/null
This command scans the entire filesystem for a file named node. Be aware that this may take some time depending on your disk size. Once you identify the correct path, add it to your PATH. For Windows users, ensure that the Node.js installation directory is included in the System Environment Variables under Path.

Updating Your Shell Configuration

The most common fix involves editing your shell's initialization file. For Bash users, this is typically ~/.bashrc or ~/.bash_profile. For Zsh users, it is ~/.zshrc. Open the relevant file in a text editor:
nano ~/.bashrc
Add the following line at the end of the file, replacing /path/to/node with the actual path you found earlier:
export PATH="/path/to/node/bin:$PATH"
If you are using a version manager like nvm, you likely already have initialization code in your config file. Ensure that the nvm setup block is present and not commented out. After saving the file, reload your shell configuration by running:
source ~/.bashrc
Or simply close and reopen your terminal window. Verify the fix by running node --version again. If you frequently switch between projects or environments, consider adding conditional logic to your config file to manage multiple Node versions efficiently. For more insights on optimizing your shell environment, see How to Improve Bash Performance and Secure Passwords.

Using Version Managers

To prevent path issues entirely, use a Node version manager like nvm (Node Version Manager), n, or fnm. These tools handle PATH updates automatically. Install nvm by following the official installation script from their GitHub repository. Once installed, install a specific version of Node.js:
nvm install 18
Then set it as the default:
nvm alias default 18
nvm will automatically update your PATH whenever you switch versions or open a new terminal session. This approach eliminates manual path configuration and reduces the likelihood of encountering command not found errors. It is particularly useful for developers working on multiple projects with different Node.js requirements.

Debugging Script Execution Contexts

Sometimes the error appears only when running a shell script rather than interactively in the terminal. This happens because scripts often run in a non-interactive, non-login shell context, which may not source ~/.bashrc or ~/.profile. To fix this, explicitly set the PATH at the beginning of your script:
#!/bin/bash
export PATH="/usr/local/bin:/usr/bin:/bin:$PATH"
# Your script commands here
node app.js
Alternatively, use absolute paths to the Node executable within your script if the PATH modification is not feasible. This ensures that the script finds Node regardless of the calling environment. If you need to write debug data to files during execution, refer to How to Write Debug Data to a Root Owned File in Bash for best practices on handling permissions and output redirection.

Checking for Symlink Issues

In some cases, the node binary exists but is broken due to a missing symlink. Check if the symlink points to a valid file:
ls -l $(which node)
If the target is missing, recreate the symlink manually or reinstall Node.js. On macOS with Homebrew, you can relink packages:
brew link node
On Linux, ensure that your user has read and execute permissions for the Node binary directory. Incorrect permissions can sometimes mimic command not found errors depending on the shell's security settings.

Frequently Asked Questions

Why does 'node' work in the terminal but not in my script?

Scripts often run in a minimal environment that does not load your interactive shell configuration files like .bashrc. To resolve this, define the PATH explicitly at the top of your script or use absolute paths to the Node executable.

How do I find where Node.js is installed?

Use the which node command in your terminal. If it returns nothing, use find / -name "node" -type f to search the entire filesystem, keeping in mind that this may require administrative privileges and time.

Can I use NVM to fix this error permanently?

Yes, using nvm is the recommended long-term solution. It automatically manages your PATH and allows you to switch between Node versions seamlessly without manual configuration errors.

What should I do if I get permission denied after fixing the path?

Ensure that the Node binary has execute permissions. You can change permissions using chmod +x /path/to/node. Additionally, verify that your user account has read access to the directory containing the Node executable.

Does changing PATH affect other applications?

Modifying your PATH generally affects all applications launched from your shell. However, adding Node.js to the front or back of the PATH usually does not conflict with other tools unless you have conflicting executables with the same name, which is rare for node.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More