358

I'm trying to install nodeJs into my Ubuntu 14.04 in order to use GruntJs.

I've read about Ubuntu different way of doing it (issues?), so this is what I've done in order to install it:

sudo apt-get install npm

sudo npm install -g grunt-cli

Typing grunt after that I've got the error:

/usr/bin/env: node: No such file or directory

So, I've tried:

curl -sL https://deb.nodesource.com/setup | sudo bash -

sudo apt-get install -y nodejs

sudo apt-get update

And trying again, and still getting the error, I've tried:

sudo add-apt-repository https://launchpad.net/~chris-lea/+archive/node.js/

sudo apt-get install -y nodejs

I've got this message:

nodejs is already the newest version.
0 to upgrade, 0 to newly install, 0 to remove and 3 not to upgrade.

I did try a cleanup just in case:

sudo apt-get autoremove

But nope, the error is still there: when I type grunt I still get /usr/bin/env: node: No such file or directory

What should I do?

KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
Rosamunda
  • 14,620
  • 10
  • 40
  • 70
  • This problem does not occur with Ubuntu 20.04. `sudo apt-file find /usr/bin/node` lists `nodejs: /usr/bin/node`. That is, installing the `nodejs` package installs the expected `node` executable program. – Raedwald Oct 12 '20 at 11:54

22 Answers22

860

Doing a symlink solves the issue:

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

(My thanks and +1 vote to bodokaiser's answer).

fedorqui
  • 275,237
  • 103
  • 548
  • 598
Rosamunda
  • 14,620
  • 10
  • 40
  • 70
  • 101
    `sudo apt-get install nodejs-legacy` creates this link too, see description at https://packages.debian.org/sid/nodejs-legacy – anatoly techtonik May 02 '15 at 12:48
  • 1
    This fix is seriously a lifesaver. Especially, if you are following the fixing permissions guide here https://docs.npmjs.com/getting-started/fixing-npm-permissions – Josh Frankel Mar 10 '16 at 17:10
  • thanks, this is help me to solved my problem on docker too https://github.com/yussan/docker-nodejs-boilerplate/tree/master/multiple-apps – yussan Jan 24 '17 at 09:28
  • I added it to `/usr/local/bin` just so I remember it's a custom symlink. – dza Feb 22 '17 at 16:57
  • when i run on mac - sudo apt-get install nodejs-legacy it says sudo: apt-get: command not found – Swift Apr 19 '17 at 10:32
  • Further information about the name conflict (resolution): https://lists.debian.org/debian-devel-announce/2012/07/msg00002.html – JonnyJD Nov 24 '17 at 12:51
  • is was `ln -s /usr/local/bin/node /usr/local/bin/nodejs` for me... just ran `which node` to find the proper place. – Artistan Jan 30 '18 at 21:43
  • ln: /usr/bin/node: Operation not permitted – rd_ Jul 09 '18 at 15:31
  • @rd_ Obviously, you are editing the /usr/bin directory. Only root can do that. – Private_GER Aug 10 '18 at 15:59
  • 12
    You should use `which node` so you get the correct path to your node. So the command would be `ln -s "$(which node)" /usr/bin/node` – technogeek1995 Apr 05 '19 at 18:37
  • ln: /usr/bin/node: Operation not permitted even with sudo. OSX. – Oliver Dixon Jun 04 '20 at 10:52
  • Doesnt work here because `/usr/bin/npm: No such file or directory` even though `Package 1:npm-3.10.10-1.6.17.1.1.el7.x86_64 already installed` – tmarois Sep 14 '20 at 13:24
  • `ln: failed to create symbolic link '/usr/bin/node': File exists` – Audiopolis Jun 24 '22 at 19:22
128

The issue is not with the version of node. Instead, it is the way NodeJS is installed by default in Ubuntu. When running a Node application in Ubuntu you have to run nodejs something.js instead of node something.js

So the application name called in the terminal is nodejs and not node. This is why there is a need for a symlink to simply forward all the commands received as node to nodejs.

sudo ln -s /usr/bin/nodejs /usr/bin/node
Shawn
  • 8,374
  • 5
  • 37
  • 60
Muhammad bin Yusrat
  • 1,433
  • 1
  • 14
  • 19
84

if you are using nvm node version manager, use this command to create a symlink:

sudo ln -s "$(which node)" /usr/bin/node
sudo ln -s "$(which npm)" /usr/bin/npm
  • The first command creates a symlink for node
  • The second command creates a symlink for npm
Mohammad Rajabloo
  • 2,567
  • 19
  • 20
69

I think you should upgrade lastest node version

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145
vanlan228
  • 815
  • 6
  • 2
29

if you are able to access node on ubuntu terminal using nodejs command,then this problem can be simply solved using -creating a symbolic link of nodejs and node using

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

and this may solve the problem

shabeer90
  • 5,161
  • 4
  • 47
  • 65
Hiro
  • 2,992
  • 1
  • 15
  • 9
26

In my case, installing nodejs-legacy solved the issue.

sudo apt-get install nodejs-legacy
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Suleyman Arslan
  • 289
  • 3
  • 4
11

Just do

$ sudo apt-get install nodejs-legacy

And it will start working.

Prabhu Nandan Kumar
  • 1,205
  • 12
  • 22
10

If you already have nodejs installed (check with which nodejs) and don't want to install another package, you can, as root:

update-alternatives --install /usr/bin/node node /usr/bin/nodejs 99
Tom Hale
  • 40,825
  • 36
  • 187
  • 242
9

I've found this is often a misnaming error, if you install from a package manager you bin may be called nodejs so you just need to symlink it like so

ln -s /usr/bin/nodejs /usr/bin/node
Ahmad Awais
  • 33,440
  • 5
  • 74
  • 56
  • 1
    Instead of adding a negative feedback, let me know here in the comment what is wrong, so I can help you with that. Since there is nothing wrong in creating a symlink especially if it helps you manage things better. – Ahmad Awais Sep 16 '16 at 14:35
  • 1
    I for my self prefer this approach. It's clean. – Muhammad Gelbana Oct 25 '16 at 11:17
8

Depending on how you installed your node, most of the time it might not be in /usr/bin/, in my own case it was I used nvm to install so my node was in ./nvm/versions.

Using this command which node I found out the path, but to make the work easier you can run this command.

nodepath=$(which node); sudo ln -s $nodepath /usr/bin/node

the above command will get the location of your node and create a link for you.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
akisoft
  • 503
  • 6
  • 12
6

When I was using gulp i got this error.

~$ gulp

/usr/bin/env: ‘node’: No such file or directory

This was removed by executing following command you have to keep in mind that /usr/bin directory has all permissions.

~$ ln -s /usr/bin/nodejs /usr/bin/node

this works for me..

Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225
Naveen Gupta
  • 306
  • 3
  • 11
  • I had the same issue, but the solution didnt worked. I check whether node is installed or not using "node -v" command, and found it missing. It must be because I upgraded from 10.04 to ubuntu 20.04 recently. – Abdeali Chandanwala Oct 13 '20 at 08:12
6

There are two solutions to this:

a) Set your PATH variable to include "/usr/local/bin"

export PATH="$PATH:/usr/local/bin"

b) Create a symlink to "/usr/bin" which is already in your PATH

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

I hope it helps.

Pavel
  • 193
  • 2
  • 9
6

Follow these commands to fix the problem.

In a terminal:

  1. Clean the entire NPM cache:

    $ sudo npm cache clean -f
    
  2. sudo npm install -g n
    
  3. Install the latest stable version of Node.js:

    sudo n stable
    

Now the latest version of Node.js was installed. Check the version using:

node -v
u32i64
  • 2,384
  • 3
  • 22
  • 36
Anandhu Raj
  • 137
  • 1
  • 6
5

In case it's installed by using snap,

sudo ln -sfn /snap/node/current/bin/node /usr/bin/node
Irfan wani
  • 4,084
  • 2
  • 19
  • 34
manish2aug
  • 113
  • 2
  • 5
4

While ln -s is the obvious easiest fix, a piece of explanation:

Because of a conflict with another package, the executable from the Ubuntu repositories is called nodejs instead of node. Keep this in mind as you are running software.

This advice comes up, when installing sudo apt-get install nodejs.

So some other known tool (I don't know what it does. While being known to ubuntu repositories, it is not installed by default in 16.04) occupies that namespace.

Would have been nice, if Ubuntu had offered an advice how to fix this 'cleanly', if not by doing by hand what otherwise the package would do. (a collision remains a collision... if+when it would occur)

Frank N
  • 9,625
  • 4
  • 80
  • 110
  • 1
    @tom-hale answer is the Ubuntu way for this. You use alternatives to specify the correct node – kervin Dec 14 '16 at 02:05
2
sudo PATH="$PATH:/usr/local/bin" npm install -g <package-name>
KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
2

For my case link did NOT work as follow

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

But you can open /usr/local/bin/lessc as root, and change the first line from node to nodejs.

-#!/usr/bin/env node

+#!/usr/bin/env nodejs

Community
  • 1
  • 1
Tanvir Ahmad
  • 273
  • 1
  • 4
  • 9
1

it's been 7 years ago and the problems still relevant and occurred.

Oke here my problem, it's similar but not exactly the same.

When I call this command from Jenkins

ssh root@xxx.xxx.xxx.xxx "pm2 restart app"

then error /usr/bin/env Node No Such file or directory

Then here my solution:

on server xxx.xxx.xxx.xxx

It relink /usr/bin/node

First: I remove the existing one with command "rm -f /usr/bin/node"

Second: I create new link with this command "ln -s /root/.nvm/versions/node/v14.17.4/bin/node /usr/bin/node"

Node version it's depends on your installation. May it help.

THe bottom line for this error is link of node.

paisuchen
  • 11
  • 3
0

Just rename the command or file name ln -s /usr/bin/nodejs /usr/bin/node by this command

0

For me the accepted answer did not yet work. I started off as suggested here:

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

After doing this I was getting the following error:

/usr/local/lib/node_modules/npm/bin/npm-cli.js:85 let notifier = require('update-notifier')({pkg}) ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:374:25) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Function.Module.runMain (module.js:442:10) at startup (node.js:136:18) at node.js:966:3

The solution was to download the most recent version of node from https://nodejs.org/en/download/ .

Then I did:

sudo tar -xf node-v10.15.0-linux-x64.tar.xz --directory /usr/local --strip-components 1

Now the update was finally successful: npm -v changed from 3.2.1 to 6.4.1

Blackbam
  • 17,496
  • 26
  • 97
  • 150
0

For those who have installed NodeJS with nvm.

If like me you have installed, uninstalled, reinstalled some versions you simply need to do this :

nvm use v14.21.1

Or whatever version you are using.

This will recreate the links to node and npm commands that where lost during your 'cleanup' :D

WannaGetHigh
  • 3,826
  • 4
  • 23
  • 31
-1
sudo nautilus 

Open file manager as admin. Go to /usr/bin and search node.That might have been broken link, so delete it. No try installing your package. It might work -worked for me

Rupak
  • 529
  • 6
  • 16