Resolving ‘node: not found’ Error when Installing npm Packages on Ubuntu

On Ubuntu, there’s a little confusion with the name of the NodeJS interpreter. Initially, it was called node, but to avoid clashes with another package, it got renamed to nodejs.

Problem

The problem arises when using npm to install packages. The npm expects to find an interpreter named node, but since it’s been renamed to nodejs, npm gets puzzled and shows an error saying it can’t find node.

The error

sh: 1: node: not found
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read /usr/share/doc/nodejs/README.Debian

But don’t worry! The solution is to create a link or a nickname (called an alias) for nodejs and name it node. This way, when npm looks for node, it’ll find nodejs happily doing its job.

Once you set this up, npm will understand that nodejs is already installed and working smoothly, even though the name is slightly different.

Solution

To fix this issue, you can create a symbolic link so that when npm looks for node, it points to nodejs, which is already installed on your system.

Follow the steps below to do that.

Find the path

First of all, find the path where the NodeJS binary is located. Execute the below command to find the path.

which nodejs

This will give you the path to the NodeJS binary, such as /usr/bin/nodejs.

Create the symbolic link

Now, create a symbolic link that points to the nodejs binary using the ln command. Here is the command below to do that.

sudo ln -s /usr/bin/nodejs /usr/bin/node

The above command will create a symbolic link named node in the /usr/bin directory that points to the nodejs executable.

Replace /usr/bin/nodejs with the actual path you found in the first step.

After running this command, try installing packages using npm again, and it should work without the node not found error.

Leave a Comment

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

Scroll to Top