Home > Web Front-end > JS Tutorial > body text

Why Does \'node --version\' Result in \'No such file or directory\' Error on Ubuntu 12.04?

Patricia Arquette
Release: 2024-11-01 14:25:02
Original
872 people have browsed it

Why Does

Resolving "No such file or directory" Error for Node on Ubuntu 12.04

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
Copy after login

If using a non-standard shell, the path to the executable should be explicitly specified:

sudo ln -s /usr/bin/nodejs /usr/bin/node
Copy after login

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
Copy after login

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
Copy after login

Additional Insights:

  • Some users have reported that running node --version in Bash prompts the error, while it works in Zsh.
  • If the symlink method fails, try the other solutions provided.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template