NodeJS interpreter name(node
) on Ubuntu has been renamed to nodejs
because of name conflict with another package. Here's what the readme.debian says:
The upstream name for the Node.js interpreter command is "node". In Debian the interpreter command has been changed to "nodejs".
This was done to prevent a namespace collision: other commands use the same name in their upstreams, such as ax25-node from the "node" package.
Scripts calling Node.js as a shell command must be changed to instead use the "nodejs" command.
However, using nodejs mucks up installing packages using npm
. Package installation fails with the following 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
How do I make npm understand that nodejs is already installed on the system but the interpreter name is different?
On Linux Mint 17, I tried both solutions (creating a symlink or using the
nodejs-legacy
package) without success.The only thing that finally worked for me was using the ppa from Chris Lea:
This installed node version 10.37 and npm 1.4.28. After that, I could install packages globally.
I fixed it unlinking /usr/sbin/node (which is linked to ax25-node package), then I have create a link to nodejs using this on command line
Because package such as karma doesn't work with nodejs name, however changing the first line of karma script from node to nodejs, but I prefer resolve this issue once and for all
Combined the accepted answer with
source ~/.profile
from the comment that has been folded and some clean up commands before. Most likely you will also need tosudo apt-get install npm
after.Simple solution from here
You can specify version by changing setup_x.x value, for example to setup_5.x
Here's another approach I use since I like n for easy switching between node versions.
On a new Ubuntu system, first install the 'system' node:
Then install n module globally:
Since the system node was installed first (above), the alternatives system can be used to cleanly point to the node provided by n. First make sure the alternatives system has nothing for node:
Then add the node provided by n:
Next add node provided by the system (the one that was installed with curl):
Now select the node provided by n using the interactive menu (select
/usr/local/bin/node
from the menu presented by the following command):Finally, since
/usr/local/bin
usually has a higher precedence in PATH than/usr/bin
, the following alias must be created (enter in your .bashrc or .zshrc) if the alternatives system node is to be effective; otherwise the node installed with n in /usr/local/bin takes always precedence:Now you can easily switch between node versions with
n <desired node version number>
.for me problem was solved by,