How to run a symlink pointing to an executable in terminal (Linux)
Solution 1
Assuming you are asking about symlinking executables in general, this should automatically work out of the box. Make sure /usr/bin/nodejs is executable by everybody, and restart the terminal. In any case, calling node
directly from anywhere in a terminal should work normally.
If node
appears to execute properly but NodeJs itself does not like being called as node
instead of nodejs
, that's a different problem.
Solution 2
There is a program "node" in Ubuntu, that has nothing to do with Node.js. Just uninstall it:
sudo apt-get remove node
(You would find the answer, if you tried whereis node
.)
Related videos on Youtube
Simon Boudrias
Updated on September 18, 2022Comments
-
Simon Boudrias over 1 year
I installed NodeJs on an Ubuntu machine, and the package have been installed as
nodejs
. Now, to run it asnode
, I created a symlink:sudo ln -s /usr/bin/nodejs /usr/bin/node
This will work if I call the symlink directly, but it don't allow me to simply call
node
to start the program.How can I resolve this?
-
FSMaxB almost 11 yearsSome more investigation: Does nodejs work when running it as "nodejs" and what exactly is the error message you get when trying to run it as "node"? Another thing: You could take a look at nvm (Node Version Manager), it's good if you need a special version of node that is not provided by the package manager.
-
Simon Boudrias almost 11 years@FSMaxB Running
nodejs
works as expected. But that's not enough as every other program rely onnode
being available as a command globally. Runningnode
don't do anything - no error message. -
FSMaxB almost 11 yearsMaybe an alias in /etc/profile can help, but this won't work if node is run by the exec systemcall. What software are you using that depend on node?
-
Simon Boudrias almost 11 years@FSMaxB I tried aliasing too, that was working in the command line, but wasn't working for executable declaring
#!/usr/bin/env node
. I have a lot of program running on node like Mocha unit test, Yeoman, Grunt, that I'd like to get running on Ubuntu. -
FSMaxB almost 11 yearsI don't really know much more to do other than trying a fresh install, but there's one idea that came to me right now: Not using a symlink but writing a bash script "/usr/bin/node" with "#!/bin/sh" and "/usr/bin/nodejs ......." inside (and somehow passing the parameters passed to the script on to nodejs, I'm not that good at bash programming)
-
Simon Boudrias almost 11 yearsOk, I don't know why, but my node symlink had to be in
/usr/sbin/node
(and not in thebin
folder)
-
-
Simon Boudrias almost 11 yearsHey, I just realized that typing the full path of the symlink works (e.g.:
/usr/bin/node
). But if I only typenode
it doesn't - do I have to set something in my PATH or in my terminal? -
FSMaxB almost 11 years@SimonBoudrias make sure your PATH variable contains "/usr/bin" you can check that by typing "env | grep PATH". It is however, very improbable that "/usr/bin" is not in your PATH variable, as your system shouldn't work properly if this was the case.
-
Simon Boudrias almost 11 years@FSMaxB It is there... (if it helps, I'm running Ubuntu in a virtual machine via virtual box)