Installing Nodejs: sh: node: command not found error

3.1K    Asked by Aalapprabhakaran in Python , Asked on Apr 22, 2021

The code I am running is as follows:

npm install -g ethereumjs-testrpc
/usr/local/bin/testrpc -> /usr/local/lib/node_modules/ethereumjs-testrpc/build/cli.node.js

The error is as follows:

sh: node: command not found
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/ethereumjs-testrpc/node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 install: `node install`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: spawn ENOENT
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! uglifyjs-webpack-plugin@0.4.6 postinstall: `node lib/post_install.js`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the uglifyjs-webpack-plugin@0.4.6 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Answered by David Piper

The first step is to install nodejs and npm. Incase, you are facing node command not found then you can use the following code:

sudo apt-get update
sudo apt-get install nodejs
For npm:
sudo apt-get install npm

Your Answer

Answer (1)

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





6 Months

Interviews

Parent Categories