Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wangzhihao opened this issue Jul 17, 2015 · 37 comments
Closed

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

wangzhihao opened this issue Jul 17, 2015 · 37 comments
Labels
root / multiuser issues Anything related to using `sudo` or `su`, or using nvm across multiple user accounts.

Comments

@wangzhihao
Copy link

This is quite weird. can anyone fix it?

sindresorhus/sublime-autoprefixer#50

http://stackoverflow.com/questions/20886217/browserify-error-usr-bin-env-node-no-such-file-or-directory

@creationix
Copy link
Collaborator

I'm not sure what there is to fix. Nvm by design doesn't install anything in your system globally. Any tool looking for a globally installed node won't find the nvm version.

You can create a symlink like is suggested in the sindresorhus/sublime-autoprefixer issue. You'll need to update this symlink if you want to switch global node versions.

@creationix
Copy link
Collaborator

Also /usr/bin/env will find the nvm version of node as long as your $PATH has been modified by nvm already. In other words, nvm modifies only your current terminal session with the knowledge of where to find the node version it has hidden away deep inside nvm itself. This is a feature. You can have multiple terminal sessions running concurrently with different versions of node in each and they won't conflict.

@wangzhihao
Copy link
Author

In my case I've added nvm to my path, but /usr/bin/env still didn't find it. Do you have any idea about it?

haozi@kingder:~$ echo $PATH
/home/haozi/.nvm/v0.10.25/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

@wangzhihao
Copy link
Author

At least this pitfall should be noted on README. It seems to many people no clue about what's wrong. especially when today most node libraries' error reporting is poor.

@creationix
Copy link
Collaborator

Are you sure /usr/bin/env can't find it?

Try running it directly from the same session where you printed $PATH.

env node

That should drop you into a node repl. Also try which node to see which node is first in your path.

@wangzhihao
Copy link
Author

env node works.
However my question is also related to strongloop. see what follows:

haozi@kingder:~/words$ echo $PATH
/home/haozi/.nvm/v0.10.25/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
haozi@kingder:~/words$ sudo slc run
/usr/bin/env: node: No such file or directory

@creationix
Copy link
Collaborator

I'll bet sudo is loosing your custom $PATH and reverting to the system or root's default path. You can try sudo env node or sudo which node to see.

@creationix
Copy link
Collaborator

Also see #43 as mentioned in the main README about sudo breaking stuff.

@wangzhihao
Copy link
Author

Yeah! I think you are right. sudo env node breaks it : )

haozi@kingder:~/words$ sudo env node
env: node: No such file or directory

@ljharb
Copy link
Member

ljharb commented Jul 18, 2015

nvm only works from a shell session in which nvm.sh has been sourced. Within editors, this tends not to work well. Additionally, use with sudo tends not to work well - nvm is for a single user, and you should never need sudo with it at all.

Why are you using sudo with nvm in the first place?

@wangzhihao
Copy link
Author

@ljharb I never sudo nvm, I tried to sudo node

@ljharb
Copy link
Member

ljharb commented Jul 18, 2015

@wangzhihao right, that's my question. sudo node should never be used or needed with nvm.

@wangzhihao
Copy link
Author

@ljharb then what should I do if I want to run node in root privilege? For example, I try to start an express server in default 80 port, which requires root to operate.

@ljharb
Copy link
Member

ljharb commented Jul 18, 2015

You definitely don't want to do that, for a number of reasons - but if you want to run node as user X, then you must install nvm and node all under user X. nvm is meant for use within a single user account, not across multiple (ie, sudo).

@wangzhihao
Copy link
Author

What's the reasons? I'm curious : )

@ljharb ljharb added the root / multiuser issues Anything related to using `sudo` or `su`, or using nvm across multiple user accounts. label Jul 18, 2015
@ljharb
Copy link
Member

ljharb commented Jul 18, 2015

Primarily security - a node program with root privileges can do anything it wants to on your system, and it's unlikely that "everything" is actually the privileges that the program truly needs. It's best to be as granular as possible about these things.

Namely, while it could be malicious code in node core or in any of your dependent modules, it's more likely that a bug exists in node core, or in any of your dependent modules - and an accidental rm -rf / (which has happened in a module before, iirc) could cause havoc if run as root.

@ljharb ljharb closed this as completed Jul 18, 2015
@wangzhihao
Copy link
Author

Okay, I got it. I will try the nginx as a reverse proxy, as told by the suggestion here. Thanks for pointing it out.

@KevinMcSun
Copy link

Try this: ln -s /usr/bin/nodejs /usr/bin/node

@ljharb
Copy link
Member

ljharb commented Mar 17, 2017

@KevinMcSun that definitely isn't a good idea; nobody calls it "nodejs" but Ubuntu, and it'd be better to correct your PATH rather than try to hack around it.

@creationix
Copy link
Collaborator

@wangzhihao fwiw, I think it's fine to run node as root on your local machine if you just want to test binding to port 80. You'll probably need to install nvm for root for it to work though.

Nvm was originally a development tool. I've seen people use it for production deployments as well. My personal practice is to hard-code the path to the node version I want in my upstart/systemd/initd script and skip nvm for production environments.

@ljharb
Copy link
Member

ljharb commented Apr 3, 2017

Alternatively, you could use authbind which works both locally and in production.

@marcosrocha85
Copy link

Just for future reference, I was trying to run sails-inverse-model over nvm at v9.6.1 and only managed to work using full script path like: sudo node /home/marcos/.nvm/versions/node/v9.6.1/bin/script_you_want.

@ljharb
Copy link
Member

ljharb commented Dec 8, 2018

@marcosrocha85 the idea is that you wouldn’t use sudo at all, and would run nvm use before invoking node directly.

@marcosrocha85
Copy link

@ljharb in my case I was running sails-inverse-model and I only managed to run that way. I don't know if the script itself has compatibility issues with nvm.

@Kielan
Copy link

Kielan commented Jul 8, 2020

There is not enough explanation in the documentation about where nvm is installing node, and what paths are or are not set. It's not a feature to have a lack of documentation.

@ljharb
Copy link
Member

ljharb commented Jul 8, 2020

@Kielan that’s not info that should really be needed by anyone; everything goes in $NVM_DIR, and changing the PATH is the only way anything could be runnable on the command line (either per version, or once with a shim).

What more explanation in the docs would you expect?

@mrsoftware

This comment has been minimized.

@igorianru

This comment has been minimized.

@sandro768

This comment has been minimized.

@ezalivadnyi
Copy link

ezalivadnyi commented Aug 24, 2021

Why does nvm automatically don't make ls for node and add it to PATH after nvm use ...? I don't want to do any additional moves to make it works after changing node versions.

@ljharb
Copy link
Member

ljharb commented Aug 24, 2021

@ezalivadnyi i'm not sure what you're asking. nvm use changes the PATH for you, and that should be sufficient.

@maltin1234
Copy link

If node works in command line but not vscode then try this.. "which node" in command line to check what directory u have it installed in.. .nvm/versions/node/v16.11.0/bin/node and then in vscode u might get the error not not found ... usr/local/bin.. so basically you do this ln -s /Users/.nvm/versions/node/v16.11.0/bin/npm /usr/local/bin/npm. So basically you need to change the directories. But first on is the on dir you get from "which node" in terminal and the second one is the dir from error message.

@Nodiril
Copy link

Nodiril commented Sep 15, 2022

@ljharb I think he's asking if it would be possible to have nvm use ... create the link in /usr/bin as opposed to having to recreate this link whenever you use a different version.

@ljharb
Copy link
Member

ljharb commented Sep 15, 2022

@Nodiril Creating a symlink doesn't make much sense, because nvm use is per-shell - a user might have dozens of tabs open at the same time, all using a different version. Which one is the symlinked one?

@Nodiril
Copy link

Nodiril commented Sep 16, 2022

@ljharb After finding an example I understand what you're saying. Node version should be set at the project level.

The reason I ended up here was when trying to debug in vscode I ended up with:

  • Executing task: tsc -p tsconfig.json
    /usr/bin/env: ‘node’: No such file or directory
  • The terminal process "/usr/bin/bash '-c', 'tsc -p tsconfig.json'" failed to launch (exit code: 127).

So I'm trying to understand what the cause is and I thought it may be because I'm using nvm instead of having node installed. When executing /usr/bin/bash -c 'tsc -p tsconfig.json' from the terminal, it executes properly.

@ljharb
Copy link
Member

ljharb commented Sep 16, 2022

vscode ships its own copy of node, bundled.

@nicekiwi
Copy link

In my case the NVM export in my .zshrc file was ordered AFTER other scripts were loaded, some that used node. Putting the NVM export first fixed the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
root / multiuser issues Anything related to using `sudo` or `su`, or using nvm across multiple user accounts.
Projects
None yet
Development

No branches or pull requests