Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path to Node.js Installation in Ubuntu

I am new to Ubuntu (linux).

I installed node.js for a project.

Recently I am getting this error on npm install.

Error: "pre" versions of node cannot be installed, use the --nodedir flag instead

I found a stack link below as

Node pre error

Under the solution it asks for the directory where node.js is installed and currently i am clueless where the nodejs is installed.

Please help me on how can I locate the directory where node.js is installed.

like image 305
Mozak Avatar asked Aug 13 '14 07:08

Mozak


People also ask

Where is Node.js installed?

If installed with package from Nodejs.org If you downloaded and run, the installer package from the nodejs.org website, the Node. js main executables files -- node and npm -- are located on the /usr/local/bin folder. With this installation method the files will be be available to all users.

How do I know if Node.js is installed on Ubuntu?

To see if Node. js is installed, type node -v in the terminal.

Where is npm located in Ubuntu?

3 Answers. You can run npm list -g to see which global libraries are installed and where they're located. Use npm list -g | head -1 for truncated output showing just the path. On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally.


2 Answers

Quick explanation

You have a version with -pre. Get rid of it and put the latest stable version from nodejs.org.

You can use which to locate a command. For your case, type which nodejs.

EDIT: The answer from your link is referring to the path of node source code, not the nodejs binary.

like image 146
radubogdan Avatar answered Oct 23 '22 20:10

radubogdan


On Ubuntu, most software can be installed from the built-in repositories. This updates it for you (even if it's sometimes a bit outdated).

To install the stable version the Ubuntu way, install the nodejs-legacy package (after uninstalling your version):

sudo apt install nodejs-legacy

To use the latest, refer to https://askubuntu.com/a/663052/438156 (my answer), or https://askubuntu.com/a/711976/438156 (bit more involved, more the Ubuntu way).

like image 1
serv-inc Avatar answered Oct 23 '22 20:10

serv-inc