Skip to content
Advertisement

Linux: How to change command to different path?

I installed nodejs on my ubuntu system. The command which nodejsgives me the following response: /usr/bin/nodejs which is correct because a nodejs -v gives me the version I installed, 0.10.25.

If I type which node instead, I get /usr/sbin/node which does nothing at all.

My question is now: How do I change the command node to /usr/sbin/nodejs so that I have a working installation for all the programs which rely on the command node?

Short: How do I execute /usr/bin/nodejs if I run node from the console?

Thanks in advance, F

Advertisement

Answer

In your .bashrc file, create an alias thus:

alias nodejs='/usr/bin/nodejs'

Don’t add whitespaces otherwise they’ll be counted. Another solution is to consider adding /usr/bin to your PATH. Know that /usr/sbin is parsed first, before /usr/bin/ but it’s not wise to swap round these two locations because in the event duplicate commands are available (as in your case) it can lead to unknown behaviour. So creating an alias is a safer solution.

EDIT: To bring your .bashrc file changes into effect, execute:

source .bashrc

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement