Nodejs vs node on ubuntu 12.04
To install Node.js on Ubuntu, run:
Due to a naming conflict with another package, Ubuntu uses the nodejs
command for Node.js. To achieve consistency, create an alias from node
to nodejs
:
Doing the above allows you to run Node.js via the node
command, a common expectation for scripts.
Naming conflicts and how to avoid them
The package naming conflict on Ubuntu stems from a non-related node
package on other Linux systems. To avoid this collision, Node.js gets the alias nodejs
on Ubuntu.
Installing nodejs-legacy
One approach to address this is installing nodejs-legacy
, which makes a link from /usr/bin/node
to /usr/bin/nodejs
:
This simplifies using Node.js as commands generally expect node
.
Opting for a different shell
If there continues to be an issue with global command-line tools, try using a modern shell like zsh
:
This shell switch makes global tools more compliant, increasing the smoothness of execution.
When node command is still elusive
If node
refuses to run despite your efforts, check both /usr/sbin/
and /usr/bin/
for the nodejs
binary. As a last resort, consider removing and reinstalling Node.js:
Using Node Version Manager (nvm)
Why and how to use nvm
If you work on multiple Node.js projects requiring different versions, nvm
can be a lifesaver! With nvm
, you can switch easily between versions, installing new ones without globally affecting the system.
Perks of using nvm
- Supports version-specific environments
- Allows easy upgrades and downgrades of Node.js versions without
sudo
- Providers smoother version management
In case the node command still doesn't work
Alternative commands
If node
continues to be problematic, npm
and nodejs
can replace it:
Repositories and operating system versions
Sometimes, issues could arise from your repositories. Check the Nodesource distributions for any common snags. Remember to always consider compatibility with your OS version. When possible, updating to a newer version of Ubuntu and Node.js could save you a headache or two.
Was this article helpful?