4

Recently working with NodeJS ect. I installed quite different packages, for different tutorials + projects. I finally ended up with this kind of configuration:

louis@louis:~$ node -v
v5.10.0
louis@louis:~$ nodejs -v
v6.2.1
louis@louis:~$ npm -v
3.8.3

Can you explain the difference between these?

JJJ
  • 32,902
  • 20
  • 89
  • 102
Louis Lecocq
  • 1,764
  • 3
  • 17
  • 38
  • 1
    What operating system are you on? Some Ubuntu packages might install Node.js as `nodejs` instead of just `node`. In fact, you seem to have two different versions of Node.js installed. – E_net4 Jun 07 '16 at 10:33
  • 2
    Although not a bad question, this looks like a question that does not belong on SO. – Randy Jun 07 '16 at 10:34
  • @randy thought the same but was not sure where to assign it with a flag. Since it is a programming tool, it does not fit into super-user, it is not highlevel enough for server fault, etc. – Toxantron Jun 07 '16 at 10:36
  • Quite agree. Sorry @randy. I also thought about it before posting my question. But there's not a lot of place with such a developer community. And as there is some post that also talk about configurations/build. It finally fit the purpose of SO. In my opinion. – Louis Lecocq Jun 07 '16 at 10:37

3 Answers3

4

Your situation

Seems you have two different versions of nodejs installed, possibly one was installed from sources and one from package manager like apt.


louis@louis:~$ node -v
v5.10.0

This returns older version of nodejs that you installed, I recommend you to remove it.


louis@louis:~$ nodejs -v
v6.2.1

This returns the current version of nodejs installed, possibly you installed it using package manager, I remember in Ubuntu it comes by nodejs executable name.

I suggest you to create link like this

sudo ln -s `which nodejs` /usr/bin/node

so it will be available using node command also.

nodejs vs node on ubuntu 12.04


louis@louis:~$ npm -v
3.8.3

This is just version of your npm program and has nothing to do with nodejs version.

Better solution

Uninstall all versions that you have and install node using nvm to switch between old/new versions easily

To install or update nvm, you can use the install script using cURL:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash

or Wget:

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash

Usage

To download, compile, and install the latest v5.0.x release of node, do this:

nvm install 5.0

And then in any new shell just use the installed version:

nvm use 5.0

https://github.com/creationix/nvm#install-script

Community
  • 1
  • 1
gevorg
  • 4,835
  • 4
  • 35
  • 52
  • 1
    Thanks for the detailled answer and explanations. NVM is a very nice tools ! It fullfill my needs ! Just 2 little thing to add/correct : - Latest version of NodeJS is v6.0.0 (=> nvm install 6.0) - NVM install you the 'node' package and not 'nodejs'. node -v => v6.0.0 nodejs -v => nodejs is currently not installed. But the problem is fixed ! Thanks everyone for the quick informations provided. – Louis Lecocq Jun 07 '16 at 10:57
3

I assume you are using ubuntu. node and nodejs are the same tool, but node is the legacy version and nodejs the current development branch.

npm however is the package manager for node(js).

Toxantron
  • 2,218
  • 12
  • 23
  • I also recommend installing node via nvm (https://github.com/creationix/nvm) in order to have a self contained and isolated development workspace for each project and also the flexibility of having multiple independent versions that don't clash with each other. – Pedro Carriço Jun 07 '16 at 10:37
  • I used 'nvm' instead of 'npm'. the latest Node version (v6.0.0) is not available yet on NPM, but is on NVM. And i have no more nodejs, but node package only now. From your point of view, is it a right way to solve the issue ? – Louis Lecocq Jun 07 '16 at 11:01
1

Here's a bit of helpful information to add to the discussion and which will hopefully help you out regarding node version clashes.

Adding the NodeJs version to your $PATH in your .bash_profile (or it may be called .bashrc or .bashconfig) file will ensure your node calls from the terminal will use the latest and not the legacy version.

Using NVM (Node Version Manager) will allow you to install and change node versions on the fly with 'nvm use 6.0.0' and is highly recommended as some NPM packages will break if using a node and npm version that isn't correct for certain npm packages in your node_modules dir. You will also have to add NVM to your $PATH in this case, but it's easy enough to do with:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

More details can be found in the link provided.

The OP's question was answered, I know, but I think pointing the OP to a better solution is also a good idea.

  • Thanks for the additional info. But here's some questions about what you said. i didn't need to add NVM to my $PATH manually. It is there by default i guess. Why do i need to add NodeJS package ? Node package seems like it is the only one useful ? What could be the problem if i use 'node' package instead of 'nodejs'. And btw, nvm use and update 'node' package. Not nodejs. (Ubuntu 12.04) – Louis Lecocq Jun 07 '16 at 11:13
  • When you enter : 'nvm install 6.0'. It install 'node' package. Not nodejs. :/ louis@louis:~/work/sd-components$ nvm install 6.0 Downloading https://nodejs.org/dist/v6.0.0/node-v6.0.0-linux-x64.tar.xz... ######################################################################## 100.0% Now using node v6.0.0 (npm v3.8.6) louis@louis:~/work/sd-components$ node -v v6.0.0 – Louis Lecocq Jun 07 '16 at 11:15
  • As I recall, Debian/Ubuntu distros come with Node installed but it's something else entirely. When you install NodeJs it clashes with the installed version that's the default version when running 'node' in the terminal. I was referring to Node as Nodejs as to clarify which particular version I was giving you more information about. Adding the fresh install of NodeJs to your path will ensure that will be the version called when calling node in your terminal. You can do it that way, or you can follow the instructions in that NVM link, which I recommend. – Nathan Stephens Jun 08 '16 at 01:06
  • The code example I provided was showing how to add NVM to your path. Let me know if you would like a description on how to add NodeJs without the version manager to your path. – Nathan Stephens Jun 08 '16 at 01:10