This is quite weird. can anyone fix it?
https://github.com/sindresorhus/sublime-autoprefixer/issues/50
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.
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.
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
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.
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.
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
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.
Also see #43 as mentioned in the main README about sudo breaking stuff.
Yeah! I think you are right. sudo env node breaks it : )
haozi@kingder:~/words$ sudo env node
env: node: No such file or directory
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?
@ljharb I never sudo nvm, I tried to sudo node
@wangzhihao right, that's my question. sudo node should never be used or needed with nvm.
@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.
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).
What's the reasons? I'm curious : )
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.
Okay, I got it. I will try the nginx as a reverse proxy, as told by the suggestion here. Thanks for pointing it out.
Try this: ln -s /usr/bin/nodejs /usr/bin/node
@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.
@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.
Alternatively, you could use authbind which works both locally and in production.
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.
@marcosrocha85 the idea is that you wouldn鈥檛 use sudo at all, and would run nvm use before invoking node directly.
@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.
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.
@Kielan that鈥檚 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?
use this comment to create a symlink:
sudo ln -s "$(which node)" /usr/bin/node
Most helpful comment
Try this: ln -s /usr/bin/nodejs /usr/bin/node