Upon attempting to run node --version on Ubuntu 12.04 after installing NodeJS, users may encounter the error "-bash: /usr/sbin/node: No such file or directory." Despite the presence of node in the /usr/sbin/ directory, it remains inaccessible to the terminal.
Solution I: Creating a Symlink
To rectify this issue, users must manually create a symbolic link from /usr/bin/node to the actual NodeJS executable. This can be achieved through the following command:
sudo ln -s `which nodejs` /usr/bin/node
If using a non-standard shell, the path to the executable should be explicitly specified:
sudo ln -s /usr/bin/nodejs /usr/bin/node
Explanation:
The naming conflict between the unrelated node package (Amateur Packet Radio Node Program) and NodeJS has led to the renaming of the latter's executable.
Solution II: Removing Conflicting Package
Alternatively, uninstalling the node package (not NodeJS) can resolve the conflict and allow node to be used without a symbolic link.
sudo apt-get --purge remove node
Solution III: Using Update-Alternatives
Another approach is to utilize update-alternatives to set the default NodeJS executable to /usr/bin/node:
sudo update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
Additional Insights:
The above is the detailed content of Why Does \'node --version\' Result in \'No such file or directory\' Error on Ubuntu 12.04?. For more information, please follow other related articles on the PHP Chinese website!