[node.js] Cannot install NodeJs: /usr/bin/env: node: No such file or directory

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?

This question is related to node.js ubuntu gruntjs npm-install node-modules

The answer is


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


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..


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.


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 somethign.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

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

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

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)


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


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

sudo apt-get install nodejs-legacy

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

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

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.


sudo PATH="$PATH:/usr/local/bin" npm install -g <package-name>

I think you should upgrade lastest node version

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

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


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


Just do

$ sudo apt-get install nodejs-legacy

And it will start working.


Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`

Examples related to ubuntu

grep's at sign caught as whitespace "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? "Repository does not have a release file" error ping: google.com: Temporary failure in name resolution How to install JDK 11 under Ubuntu? How to upgrade Python version to 3.7? Issue in installing php7.2-mcrypt Install Qt on Ubuntu Failed to start mongod.service: Unit mongod.service not found

Examples related to gruntjs

NPM vs. Bower vs. Browserify vs. Gulp vs. Grunt vs. Webpack Karma: Running a single test file from command line Cannot install NodeJs: /usr/bin/env: node: No such file or directory Tried to Load Angular More Than Once Difference between Grunt, NPM and Bower ( package.json vs bower.json ) What does -save-dev mean in npm install grunt --save-dev grunt: command not found when running from terminal Grunt watch error - Waiting...Fatal error: watch ENOSPC How to install grunt and how to build script with it "Fatal error: Unable to find local grunt." when running "grunt" command

Examples related to npm-install

How to update core-js to core-js@3 dependency? Can not find module “@angular-devkit/build-angular” How do I deal with installing peer dependencies in Angular CLI? NPM Install Error:Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0' How to solve npm install throwing fsevents warning on non-MAC OS? Why does "npm install" rewrite package-lock.json? What is the difference between npm install and npm run build? How to solve npm error "npm ERR! code ELIFECYCLE" base 64 encode and decode a string in angular (2+) Install specific branch from github using Npm

Examples related to node-modules

SyntaxError: Cannot use import statement outside a module What could cause an error related to npm not being able to find a file? No contents in my node_modules subfolder. Why is that? Node - was compiled against a different Node.js version using NODE_MODULE_VERSION 51 npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Nuwanst\package.json' Cannot find the '@angular/common/http' module How to use paths in tsconfig.json? Could not find a declaration file for module 'module-name'. '/path/to/module-name.js' implicitly has an 'any' type How to fix 'fs: re-evaluating native module sources is not supported' - graceful-fs How to provide a mysql database connection in single file in nodejs Git - Ignore node_modules folder everywhere