3

Simple question - How to update nodejs from 6.x to 8.x? I have Ubuntu 16.04. Should I uninstall older version and install new one? If so, how can I do this. A tried sudo n latest but it says sudo: n: command not found and when i just n latest is requires sudo Wtf?

Kirill
  • 207
  • 1
  • 4
  • 14

3 Answers3

9

Use Node version manager:

For development systems you may test different versions so you may want to switch between versions on demand. This is possible using the nvm version manager. This allows you to try out your code in different versions and find problems.

Install it using the script:

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

Then you may directly use it. It can install other versions and switch between versions easily.

Some of the commands are:

nvm current     display currently activated version
nvm ls [<version>]  list installed versions
nvm ls-remote [<version>]   list versions available for install
nvm version <version>   get best matching installed version
nvm version-remote <version>    get best matching remote version
nvm install <version>   download and install a version
nvm uninstall <version>     uninstall a version
nvm use <version>   modify path to use version
nvm which <version>     show path there this version is installed

So to install node 8 call

$ nvm install 8

And to upgrade to new node version later:

$ nvm current
v8.0.0
$ nvm version-remote 8
v8.1.0
$ nvm install 8.1 --reinstall-packages-from=8.0
Downloading and installing node v8.1.0...
Downloading https://nodejs.org/dist/v8.1.0/node-v8.1.0-linux-x64.tar.xz...
######################################################################## 100,0%
Computing checksum with sha256sum
Checksums matched!
Now using node v8.1.0 (npm v5.0.3)

Reinstalling global packages from v8.0.0...
added 9 packages and updated 1 package in 2.463s
Linking global packages from v8.0.0...

But after you changed your node version you should call npm install in your module again.

Alinex
  • 914
  • 8
  • 18
1

Use this command for ubuntu

sudo npm install npm@latest -g
sudo npm cache clean -f
sudo npm install -g n
sudo n stable

//for latest release

   `sudo n latest
karthik006
  • 886
  • 9
  • 19
0

You have something called nvm (Node Version Manager)

To see all versions of node/nodejs type in terminal: "node ls-remote"

to install a specific version type in terminal: "nvm install 10.15.2" (for version 10.15.2 as an example)

Hadi Abu
  • 1,359
  • 1
  • 10
  • 14