48

I am using Ubuntu Linux.

How can I check current nodejs version? I guess, I have 6 version, but I am not sure.

And is there way to change it, because I need 4 version. Can some one give step by step commands?

halfer
  • 19,824
  • 17
  • 99
  • 186
Headmaster
  • 2,008
  • 4
  • 24
  • 51
  • Possible duplicate of [Node.js version on the command line? (not the REPL)](https://stackoverflow.com/questions/14888471/node-js-version-on-the-command-line-not-the-repl) – alexmac Aug 11 '17 at 10:07
  • You can use NVM (Node version management) to manage multiple active node.js versions. https://github.com/creationix/nvm – Andan H M Aug 11 '17 at 10:11

5 Answers5

75

Open up the terminal and type node -v

To change your node version, I'd recommend installing nvm. Once installed, to switch versions it's as simple as

nvm use <version>
James
  • 80,725
  • 18
  • 167
  • 237
25

You can check your current NodeJS version by using command node -v. And changing your version can be done by using node version manager. The easiest way to do that is by running this $ npm install -g n now you can change your current NodeJS version using n (version) e.g. n 4.0.0.

node -v
npm install -g n
n 4.0.0
Pavan Vora
  • 1,634
  • 14
  • 19
  • 3
    This does not change the active version. How do I change to the stable version, for instance. I tried:
    # n latest
    installing : node-v15.7.0
    mkdir : /usr/local/n/versions/node/15.7.0
    fetch : https://nodejs.org/dist/v15.7.0/node-v15.7.0-linux-x64.tar.xz
    installed : v15.7.0 to /usr/local/bin/node
    active : v10.13.0 at /opt/conda/bin/node
    # n stable
    installed : v14.15.4 to /usr/local/bin/node
    active : v10.13.0 at /opt/conda/bin/node
    – Kurt Peters Jan 28 '21 at 23:29
  • Yes, this is annoying, what I ended up doing was removing node (https://askubuntu.com/questions/786015/how-to-remove-nodejs-from-ubuntu-16-04) and then you can either symlink /usr/local/bin/[node~npm] into /usr/bin or you can add /usr/local/bin to your path. – satnhak Feb 25 '21 at 21:29
  • NOTE: When you run it, n will inform you that node might not report the correct version until you restart your CLI. So, be sure to do so – ldobson Oct 08 '22 at 18:53
10

You can check your version by using this code (node -v) in linux terminal and If you want to upgrade it to stable version you can use following codes one by one.

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Dinith
  • 839
  • 14
  • 22
2

Just type npm version in your command line and it will display all the version details about node, npm, v8 engine etc.

Himanshu
  • 6,983
  • 1
  • 15
  • 9
2

To change your node version, I'd recommend installing nvm. Once installed, switch versions follow the instruction below;

nvm use <any specified version you prefer "example v16.0.0">

Example:

nvm alias default 16

This will enforce as the current default version.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31