12

I installed nodejs with apt-get on 14.04

When I do nodejs -v

v0.10.25

and when i do node -v

node : command not found.

So I want to alias of nodejs to node

I inserted a line in ~/.bashrc

alias node=nodejs

Now I can access nodejs with node in a terminal.

But in my project, i use grunt which fires nodemon via gruntfile.js. Now nodemon tries to run node instead of nodejs

So again I get the same problem node : command not found.

So the alias doesn't work for non-interactive non-login shells.

Where should I make the alias for this specific purpose and get my problem solved?

Zanna
  • 70,465
  • Please add the same alias in /etc/profile and restart; after changing any rc file or profile file you must source it. – PradyJord Jun 06 '14 at 09:27
  • @Jord i edited /etc/profile with same alias and restarted. But still the problem is same. – codeofnode Jun 06 '14 at 09:51
  • Several years late, but... aliases won't (normally) work in a non-interactive shell: http://stackoverflow.com/a/1615973/7222080 Follow the symlink advice in the answers. – John N Dec 14 '16 at 09:36

3 Answers3

12

Recently fixed this using nodejs-legacy.

Run the following command:

sudo apt-get install nodejs-legacy

This should fix it.

11

Well curiously, I have a node. It's an alternatives system symlink and I'm not quite sure how I got it (in a way that you don't). It was a while since I installed it so perhaps I followed this SO post or one like it... Who knows!

You could just write a little bash alias but that'll only work for one user at a time. It might just make more sense to add it as as symlink globally. I'm not sure there's any value going through the alternatives system so we can just plonk one in /usr/local/bin (this is where non-package-managed binaries should go):

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

Edit: That SO post I talked about actually links back to one of ours which might be relevant. It suggests installing nodejs-legacy is the way forward.

Oli
  • 293,335
  • 1
    Find the location of nodejs via whereis nodejs then do ln -s /usr/bin/nodejs ~/bin/node (yes, no sudo there); replace /usr/bin/nodejs with the path your nodejs is at – srcspider Apr 27 '15 at 11:13
  • 3
    going backwards is not the way forward – srcspider Apr 27 '15 at 11:14
0

Since the bin directory is already in the PATH, you can simply create a symlink called node in the ~/bin directory linking to the actual binary.

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