If you encounter the "sh: node: command not found" error after installing Node.js, it means that the Node.js executable is not found in your system’s PATH. Here are the steps to troubleshoot and resolve this issue:
1. Verify Installation
Ensure that Node.js has been installed correctly. You can check if Node.js is installed by running:
bash
Copy code
node -v
npm -v
If these commands return a version number, Node.js is installed correctly.
2. Check Installation Path
Ensure that the installation path of Node.js is included in your system’s PATH environment variable.
On Unix/Linux/Mac:
Open your terminal and check the PATH variable:
echo $PATH
If Node.js is not in the PATH, you need to add it. For example, if Node.js is installed in /usr/local/bin, you can add this path to your PATH variable by adding the following line to your ~/.bashrc, ~/.bash_profile, or ~/.zshrc file:
export PATH=$PATH:/usr/local/bin
After adding this line, reload the terminal configuration by running:
source ~/.bashrc # or ~/.bash_profile or ~/.zshrc
On Windows:
Open Command Prompt and check the PATH variable:
echo %PATH%
If Node.js is not in the PATH, you need to add it:
Right-click on ‘This PC’ or ‘Computer’ on the desktop or in File Explorer and select ‘Properties’.
Click on ‘Advanced system settings’.Click on the ‘Environment Variables’ button.
In the ‘System variables’ section, find the Path variable and click ‘Edit’.
Add the path to the directory where Node.js is installed (e.g., C:Program Files
odejs).
Click ‘OK’ to close all dialog boxes.
3. Reinstall Node.js
If the issue persists, consider reinstalling Node.js. Download the latest version from the official Node.js website and follow the installation instructions for your operating system.
4. Check for Symlink Issues (Unix/Linux/Mac)
On Unix-based systems, the node executable might not be symlinked correctly. You can create a symlink manually:
sudo ln -s /usr/local/bin/node /usr/bin/node
5. Use Node Version Manager (NVM)
Using Node Version Manager (NVM) can simplify managing Node.js versions and their paths. Install NVM and use it to install Node.js:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc # or ~/.bash_profile or ~/.zshrc
nvm install node
nvm use node