812

So, I have Node.js installed and now when I tried to install Mongoosejs I got an error telling me that I don't have the needed version of Node.js (I have v0.4.11 and v0.4.12 is needed).

How can I upgrade to this version? I suppose I just could install it again with the latest version, but I don't want to do it before I'm sure that my project folders in the folder "node" won't be deleted.

alex
  • 438,662
  • 188
  • 837
  • 957
holyredbeard
  • 15,990
  • 29
  • 94
  • 163
  • 10
    For windows, just reinstall nodejs using the latest installer. – laike9m Jun 02 '14 at 11:33
  • I reinstall nodeJS on windows a few times but it didn't help, I think it has something to do with visual studio 2015 – Farzad J Nov 21 '16 at 15:46
  • Things have gotten quite a bit easier since this question was first answered (if you don't need version management) : [All platforms (Windows, Mac & Linux)](https://stackoverflow.com/a/33010229/2768271) – swelet Nov 04 '17 at 07:07
  • Possible duplicate of [How do I update Node.js?](https://stackoverflow.com/questions/8191459/how-do-i-update-node-js) – Aniket Thakur Nov 07 '17 at 10:43

34 Answers34

1359

Ubuntu Linux/Mac:

The module n makes version-management easy:

sudo npm install n -g

For the latest stable version:

sudo n stable

For the latest version:

sudo n latest

Windows:

just reinstall node from the .msi in Windows from the node website.

Casimir Crystal
  • 18,651
  • 14
  • 55
  • 76
Eldar Djafarov
  • 19,573
  • 2
  • 31
  • 27
  • 1
    Thanks for the answer. I installed it and the following message was shown: n@0.7.1 ../node_modules/n. When I type "n 0.4.12" I get the message that the command wasn't found. Do I need to be in a specific folder to use "n"? – holyredbeard Apr 09 '12 at 16:21
  • 46
    "npm install -g n" did it! – holyredbeard Apr 09 '12 at 17:45
  • 1
    yeah, you are totally right -g for installing it globally. BTW, Isn't it awesome? – Eldar Djafarov Apr 09 '12 at 19:11
  • Is there any way to upgrade to the latest version using `n`, instead of specifying the version? – Anderson Green Jan 17 '13 at 21:50
  • sudo npm cache clean -f sudo npm install -g n sudo n stable – laycat May 13 '13 at 08:44
  • Is there anything similar for Win? – ZenMaster Jul 08 '13 at 05:06
  • 8
    @ZenMaster just reinstall node from the `.msi` in Windows from the node website. No need for n – Naftali aka Neal Aug 16 '13 at 15:48
  • @vsync see my comment above ^ – Naftali aka Neal Aug 16 '13 at 15:49
  • I lack the rep to do this, but `For the latest version:` would better read `Use n to install the latest stable node:` – Peter Ehrlich Sep 12 '13 at 19:15
  • Upgrading on Windows is so easy you don't even need to know these tricks – Bron Davies Feb 18 '14 at 00:22
  • Note that you may need to run `npm config set registry http://registry.npmjs.org/` – Richard Mar 19 '14 at 05:21
  • AWFUL idea. Does not work on Windows, and ruins your installation on non-x86 systems. Please update your answer to at least reflect these warnings. – Domi Aug 07 '14 at 09:09
  • I needed to run `sudo npm cache clean -f` before I got rid of some errors. – Sung Cho Dec 21 '14 at 20:48
  • I have upgraded my node from v0.10.31 to v0.12.0 on Ubuntu 14.04. Works likes a charm. – Jingguo Yao Mar 08 '15 at 01:10
  • 1
    For all those suggesting the MSI, that's not an alternative because it doesn't replicate the behavior of this plugin (making installing/switching easy). Also as nice as this plugin in is for those that can use it, it's not in the spirit of Node because it uses BASH and thus doesn't work on Windows and Windows IS a first-class citizen with Node. – rainabba Jul 09 '15 at 19:38
  • I needed to run `sudo ln -s /usr/bin/nodejs /usr/bin/node` as the first command. Otherwise I was getting `/usr/bin/env: node: No such file or directory` – Martin Vseticka Aug 14 '15 at 14:39
  • 6
    OSX Yosemite, `npm install n -g && n stable` worked for me. No need for `sudo` if node was not previously installed with it. – Stephan Bijzitter Nov 04 '15 at 17:36
  • 3
    This answer is out of date. The best way to install/upgrade nodejs is to use **Node Version Manager** here: https://github.com/creationix/nvm or [read this answer below](http://stackoverflow.com/a/12570971/404699) – steampowered Apr 09 '16 at 17:44
  • It doesn't replace existing version, it has installed the new one to `/usr/local/n/versions/node/7.8.0` If you don't add it to the path, use `n use latest yourscript.js` to launch your script with the installed version of node – pdem Apr 26 '17 at 08:31
  • sudo su will simplify to run the command under administrative rights – Faris Rayhan May 22 '17 at 03:56
  • In Linux, you have to create a softlink as well. refer the accepted answer here. https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version – Jacob Nelson Dec 13 '17 at 01:32
  • 2
    When use command 'node -v' to check whether upgrade success, remember to open a new terminal, otherwise you will still see the old version displayed. – Jeff7566 Nov 18 '18 at 03:34
  • I've tried this solution several times, and closed and reeopened the terminal and still have v6.11.3 which is ridiculously outdated. This solution doesn't come close to working for Centos 7. – Altimus Prime Dec 30 '18 at 21:47
  • i have also tried didn't worked after doing sudo n stable node latest version got downloaded but reopen the terminal and checked still the old version – DILEEP THOMAS Feb 22 '19 at 03:48
  • I suggest using the more up to date answer below (without using Sudo). NVM is far more developer friendly and your less likely to end up with permission issues. – WillW Apr 08 '19 at 22:04
  • Please remove _sudo_ from _sudo npm_. It's not a good practice to use sudo with npm, so it shouldn't be incentivized ([ref](https://medium.com/@ExplosionPills/dont-use-sudo-with-npm-5711d2726aa3)) – jose Mar 17 '20 at 17:59
607

1 Minute Solution Without using sudo:

The current stable "LTS" version of node is 14.17.0 (2021-05-20) see: nodejs.org for latest.

Step 1 - Get NVM (Node Version Manger)

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

If you're curious about the installation command read the source code
... its been reviewed by several node.js security experts

Step 2 - Install the version of node.js you need

Once you've got NVM you can install a specific version of Node.js using the nvm command:

nvm install v14.17.0

Note: you may need to close & re-open your terminal window for nvm command to be available.

You should expect to see something like this in your terminal:

Now using node v14.17.0

Step 3 - Enjoy the rest of your day!

Yes, it's that easy and didn't require sudo!
Now please Upvote this (so others can avoid sudo-installing things!)
and have a lovely day writing node.js code!

Microsoft Windows User? Use: https://github.com/coreybutler/nvm-windows

 tl;dr

Review of the node mailing list indicates that using NVM (Node Version Manager) is the preferred way to manage your nodejs versioning/upgrading. see: github.com/nvm-sh/nvm

NVM is considered "better" than N because the verbose commands mean is much easier to keep track of what you are doing in your Terminal/SSH Log. Its also faster, saves kittens by not requiring sudo and is used by the team at NPM the node.js security experts!

nelsonic
  • 25,667
  • 19
  • 83
  • 109
  • I need version 0.8 to install grunt-contrib and nvm seems to provide only up to 0.6. This seems to rule out nvm as an option for me. – carbontax Nov 24 '12 at 00:06
  • Yeah, there's an issue for it on GitHub: https://github.com/creationix/nvm/issues/90 – nelsonic Nov 27 '12 at 19:35
  • I ended up building from source. But perhaps I will switch to nvm in the next release. Thanks nelsonic – carbontax Nov 27 '12 at 20:20
  • 2
    None of them are supported in Windows. NVM suggests [nvmw](https://github.com/hakobera/nvmw) and [nvm-windows](https://github.com/coreybutler/nvm-windows) that are "neither supported nor developed by" NVM and I havent testsed out yet. @nelsonic your answer is awesome – slevin Oct 04 '15 at 10:26
  • `nvm` installs into a user's home directory. So if you use another tool to manage node processes, such as **pm2**, then you need to specify the new name of the node process (`nodejs` vs `node`) in order to experience the version nvm sets (if going from v0.12.x to v4.x for example). This is because nvm links `node` to `nodejs` only under the installed user's profile. – steampowered Apr 11 '16 at 21:59
  • I must say that I was unable to change nodejs version usinv `n`. Everything was running fine, no errors, but the version after `n stable` was still `5.3.0` even though it should be `6.0.0` at the time of writing. Anyway, installed `nvm` , installed `6.1.0` and everything works. I'm on root user, no `sudo` needed anyway. – Eduard May 13 '16 at 09:25
  • After installing nvm and using command `nvm install v6.9.1`, I got this `Version 'v6.9.1' not found - try 'nvm ls-remote' to browse available versions.` . Even after I use `nvm ls-remote`, I got **N/A** . Currently I have _v6.3.0_ – Ankur Shah Nov 16 '16 at 20:11
  • Hi @AnkurShah please raise an issue on GitHub: https://github.com/creationix/nvm/issues (_thanks_!) – nelsonic Nov 17 '16 at 13:11
  • 3
    I have used [nvm-windows](https://github.com/coreybutler/nvm-windows) for quite a while now. Seems pretty solid. – Alastair Sep 14 '17 at 17:31
  • Shouldn't `tl;dr` be at the top for all the people that don't read – BotNet Sep 29 '17 at 14:57
  • 1
    I took one look at step one and already I didn't like this solution. The curl command includes a version number on nvm. I'd rather have a command that installs the latest version. Does nvm take care of that on its own? I also don't like step 2. I'd prefer a command that installs the latest version, and doesn't require me to know a version number. – MiguelMunoz Mar 31 '18 at 15:08
  • "=> You currently have modules installed globally with `npm`. These will no => longer be linked to the active version of Node when you install a new node => with `nvm`; and they may (depending on how you construct your `$PATH`) => override the binaries of modules installed with `nvm`:" WTF?? so it does not do dependency check? NVM needs to learn from RVM – Luis Flores Jul 20 '18 at 20:19
  • @LuisFlores agree that NVM could learn from RVM. see: https://github.com/creationix/nvm/issues/1418 – nelsonic Jul 21 '18 at 12:43
  • Unfortunately, nvm [doesn't support](https://github.com/creationix/nvm/blob/master/README.md#important-notes) Fish shell. Just run `bash` and when you're done, go back to Fish (run `exit`) – Lytvoles Jul 04 '18 at 15:08
  • I needed to run `source ~/.nvm/nvm.sh` to make nvm available for terminal. – Patrik Rikama-Hinnenberg Jan 31 '19 at 20:39
  • it working fine thank you to submit your anwer @nelsonic – Naved Khan Mar 08 '19 at 09:17
  • just a heads up for those using something other than the bash shell. run the curl command with the shell you're using eg: `{command} | zsh` – Beefjeff May 21 '19 at 16:40
  • I am wondering, why should i even search this in SO... Probably Node people could make better job. Tnx for solution. – Dzintars Jun 09 '19 at 12:48
  • I still have to use `sudo` to install versions because it says `mkdir: cannot create directory '/usr/local/nvm/alias': Permission denied` – redOctober13 Jun 27 '19 at 19:04
  • 1
    @redOctober13 sounds like you need to fix your permissions. see: https://github.com/nvm-sh/nvm/issues/1164#issuecomment-248749969 You should avoid using `sudo` (root access) wherever possible. – nelsonic Jun 27 '19 at 20:32
  • 1
    It's work on ubuntu 18.04 I got the latest version with: nvm install v12.6 – Ananda Bayu Putra Yudhistira Jul 12 '19 at 17:22
  • Good answer but... why use a random developer's (`creationix`) script and not the official `nvm` installation: `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash` – Dimitris Jul 17 '19 at 16:49
  • If you already have existing packages in a similar node version (ex: 12.7) try this `nvm install 12.13 --reinstall-packages-from=12.7`. This will prevent you from having to reinstall necessary global modules like yarn, Gatsby, etc. – Yatit Thakker Nov 08 '19 at 00:29
83

via npm:

npm cache clean -f
npm install -g n
n stable

and also you can specify a desired version:

n 0.8.21

reference

Yehuda Schwartz
  • 2,459
  • 1
  • 21
  • 32
jics
  • 1,114
  • 1
  • 9
  • 21
58

On Windows download latest "Windows Installer (.msi)" from https://nodejs.org/download/release/latest/ and install same directory , thats all...

After complete the installation above, the NodeJS and NPM will be upgraded to the latest one and then you can cleanup the package as normal as:

npm cache clean
npm update -g

Note

You can always check the version with following command:

C:\node -v
v0.12.4

C:\npm -version
2.10.1
CODE-REaD
  • 2,153
  • 3
  • 25
  • 54
Erdi
  • 1,602
  • 3
  • 17
  • 25
  • I have installed these versions of node and I have Windows 10 installed. I have installed express and jade globally but in my project `npm install express` not working. Do you have any solution? – Jai May 30 '15 at 14:07
  • Now you should run `npm cache verify` not `npm cache clean` – Rami Alloush Dec 20 '19 at 17:37
50

All platforms (Windows, Mac & Linux)

Updated May 2021

That's it folks. It used to be more complex and people used different kinds of packages and strategies to manage it. But things have changed for the better.

Just go to nodejs.org and use the latest installer.

swelet
  • 7,118
  • 5
  • 27
  • 40
  • 1
    This worked - but first had to manually remove the existing binary. I copied into a backup location to be safe `mv /opt/local/bin/node ~/tmp/` – Gene Bo May 23 '17 at 00:04
  • @gnB What kind of error did you get? I'll include it in the answer. – swelet May 23 '17 at 20:38
  • This came up while working with Firebase CLI, which requires the latest node install. I didn't get an error - but every time I tried to run the CLI command `firebase deploy`, it kept referencing the old version/install that had like `0.12.12` in it.. and so firebase kept giving me an error saying I need to upgrade. After I did the remove line (from my initial comment), then the correct `6.x` version/install was detected – Gene Bo May 23 '17 at 20:50
  • 1
    just downloaded newest version, install, went to command prompt typed `node -v`, saw change instantly. – Vincent Tang Mar 30 '18 at 15:22
  • Just adding for the less experienced ones, that after downloading the binary, there is a bit of installation process, as described here: https://medium.com/@tgmarinho/how-to-install-node-js-via-binary-archive-on-linux-ab9bbe1dd0c2. – Shoval Sadde May 19 '20 at 13:33
22

Upgrading node.js to the latest version on Windows

  1. Install chocolatey if you haven't already: Installing Chocolatey

  2. From the command prompt, type

    cup nodejs

(which is equivalent to typing choco upgrade nodejs -- assumes you already have node installed)

NOTE: You may need to run cinst nodejs.install for chocolatey to register your existing installation. (thanks for the comment, @mikecheel)


Installing node.js on Windows

If you have never installed node, you can use chocolatey to do that as well. Install chocolatey (see step 1 above). Then from a command prompt, type:

cinst nodejs.install

Chocolatey Gallery Node JS (Install)


Installing a specific version of node on Windows with chocolatey

cinst nodejs.install -Version 0.10.26

Community
  • 1
  • 1
Jon Crowell
  • 19,362
  • 12
  • 81
  • 104
  • 2
    I had to run choco install nodejs.install for it to see my existing installation. – Mike Cheel Oct 27 '14 at 16:29
  • Make sure to run command prompt as administrator. (choco will warn you) – Radmation Jul 22 '18 at 19:11
  • Whats funny is I had node v 6 installed but when I tried to run `cup nodejs` it told me i didn't have nodejs installed at all. It asked if i wanted to install and I selected yes. When I run node -v i get version 10.7.0 so all is well! Thanks! – Radmation Jul 22 '18 at 19:13
20

Following Upgrading Node.js to latest version

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

sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/node

For Upgrading Node.js to latest version

sudo n latest

If you need to do Undo then follow command

sudo apt-get install --reinstall nodejs-legacy     # fix /usr/bin/node
sudo n rm 6.0.0     # replace number with version of Node that was installed
sudo npm uninstall -g n

This method of upgrading node is now unstable and should not be used. The best way to manage Node.js versions is to use NVM: Node Version Management.!

Installation

You can read the installation steps on the nvm [GitHub page][1]. There are only two easy steps for installation and configuration. Using nvm

If you work with a lot of different Node.js utilities, you know that sometimes you need to quickly switch to other versions of Node.js without hosing your entire machine. That's where you can use nvm to download, install, and use different versions of Node.js:

nvm install 4.0

At any given time you can switch to another with use:

nvm use 0.12
Toshinou Kyouko
  • 306
  • 9
  • 20
Sagar Jethi
  • 1,185
  • 11
  • 17
  • This fixed my problem. Apparently, after updating the node needs a linking to the newer version – Gibs Apr 29 '21 at 04:04
14

For brew users on Mac OSX

brew upgrade node

Which produces:

Andrews-MacBook-Air :: ~/dev/cookiecutter-ionic ‹master*› » brew upgrade node
==> Upgrading 1 outdated package, with result:
node 0.12.7
==> Upgrading node
==> Downloading https://homebrew.bintray.com/bottles/node-0.12.7.yosemite.bottle
######################################################################## 100.0%
==> Pouring node-0.12.7.yosemite.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
  /usr/local/Cellar/node/0.12.7: 2726 files, 31M
agconti
  • 15,820
  • 15
  • 69
  • 108
12

Install npm =>

sudo apt-get install npm

Install n =>

sudo npm install n -g

latest version of node =>

sudo n latest 

So latest version will be downloaded and installed

Specific version of node you can

List available node versions =>

n ls

Install a specific version =>

sudo n 4.5.0
Sunil Garg
  • 10,122
  • 12
  • 92
  • 133
Gurudath BN
  • 1,242
  • 19
  • 21
10

I had node version v7.10.0 in Ubuntu

Used below commands to upgrade

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Now its upgraded to v8.2.1

or

sudo apt-get install make
sudo curl -L https://git.io/n-install | bash
. /home/$USER/.bashrc

# Below command should get the latest version of node
node --version

# Install specific version of node
n 8.2

# Check for the Node Version installed
node --version
Sharath
  • 1,874
  • 3
  • 27
  • 58
8

sudo npm install n -g sudo n 0.12.2

or

sudo npm install -g n sudo n latest

or

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

These work well. But for UX term terminal node -v did not show latest version so I have closed and reopened new terminal. I found v10.1.0, output of node-v after installation by sudo n latest

Partha Sen
  • 2,399
  • 15
  • 15
7

Using brew and nvm on Mac OSX:

If you're not using nvm, first uninstall nodejs. Then install Homebrew if not already installed. Then install nvm and node:

brew install nvm
nvm ls-remote    # find the version you want
nvm install v7.10.0
nvm alias default v7.10.0    # set default node version on a shell

You can now easily switch node versions when needed.

Bonus: If you see a "tar: invalid option" error when using nvm, brew install gnu-tar and follow the instructions brew gives you to set your PATH.

Peter Tseng
  • 11,991
  • 3
  • 64
  • 53
6

my 2c:

I tried both with n and with nvm on Linux Ubuntu 12.04 LTS, in order to update node from v0.8.25 to v0.10.22.

The first one was successfully completed, but the command 'which node' resulted in the old v0.8.25.
The second one was successfully completed and the same command resulted in v.0.10.22.

sthor69
  • 588
  • 1
  • 9
  • 24
6
brew upgrade node

will upgrade to the latest version of the node

David
  • 709
  • 1
  • 9
  • 12
5

If you are using Linux .. Just do the following steps sudo -i sudo apt install curl curl -sL https://deb.nodesource.com/setup_10.x | sudo bash - sudo apt-get install -y nodejs you should have now the latest version

Smaillns
  • 1,330
  • 12
  • 19
4

You don't need to worry about an upgrading process.

You can just install the newest version using the official documentation as if you didn't have it installed and it will work like a charm. > https://nodejs.org/en/download/package-manager/ ;)

Marcelo Lazaroni
  • 7,543
  • 2
  • 30
  • 36
  • By far the simplest answer! Easy to forget that there is a perfectly good installer for Node that works just like any other (unless you're desperate to use a CLI). – Steve Pettifer Dec 16 '16 at 09:24
3

Open the package.json file of the node.js project and replace the version number specified with * in the dependencies will fetch you the latest version.

3

Its very simple in Windows OS.

You do not have to do any uninstallation of the old node or npm or anything else.

Just go to nodejs.org

And then look for Downloads for Windows option and below that click on Current... Latest Feature Tab and follow automated instructions

It will download the latest node & npm for you & discarding the old one.

Dharman
  • 21,838
  • 18
  • 57
  • 107
Alok Ranjan
  • 545
  • 7
  • 8
2

If you are looking in linux..

npm update will not work mostly am not sure reason but following steps will help you to resolve issue...

Terminal process to upgrade node 4.x to 6.x.

 $ node -v
 v4.x

Check node path

$ which node
/usr/bin/node

Download latest(6.x) node files from [Download][1]

[1]: https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz and unzip files keep in /opt/node-v6.9.2-linux-x64/.

Now unlink current node and link with latest as following

$ unlink /usr/bin/node
$ ln -s /opt/node-v6.9.2-linux-x64/bin/node node
$ node -v
$ v6.9.2
BEJGAM SHIVA PRASAD
  • 1,470
  • 1
  • 14
  • 23
2

There is good explanation for linux users how to update node version step by step. P.S type instead of sudo n stable sudo n latest for receive latest node version.

If you receive following error

Error: Module version mismatch. Expected 48, got 46.

You have just rebuilt npm by the following command npm rebuild it should fix the problem.

Michael Horojanski
  • 3,617
  • 4
  • 27
  • 32
2

For Windows users, simply go to the node.js (nodejs.org) website and download the latest version (8.6.0 as of 09/29/2017). Follow the steps from the auto install window and you're good to go. I just did it and when I checked my latest version in webstorm, it was already there.

2

Re-install the latest version of nodejs by downloading the latest .msi version from nodejs website here, https://nodejs.org/en/download/

It worked for me in my windows machine.

manian
  • 1,378
  • 2
  • 11
  • 27
2

just try this on your terminal :

nvm install node --reinstall-packages-from=node

it should do the trick.

later, run node --version to check the version that you have.

1

After install nvm as @nelsonic describes, this is the easiest way to keep it upgraded:

"node" is a shortcut to the last version, so you can install the last version with:

nvm install node

And to always use the "node" version:

nvm alias default node

Finally to upgrade your node version and keep the installed packages:

nvm install node --reinstall-packages-from=node
Community
  • 1
  • 1
Francisco Kahil
  • 174
  • 1
  • 4
1

I used https://chocolatey.org/install

  1. install chocolatey refering this https://chocolatey.org/install
  2. run in cmd

cup nodejs

That's all. NodeJs now updated to latest version

Jayani Sumudini
  • 1,164
  • 1
  • 16
  • 26
0

For Windows

I had the same problem, I tried to reinstall and didn't worked for me.

Remove "C:\Program Files(x86)\nodejs" from your system enviorment PATH and thats it!

Gökhan Kurt
  • 7,851
  • 1
  • 23
  • 48
0

Just bundling node and npm updates to latest version into a single command for my ~/.bash_profile:

update-node(){
  sudo n latest;
  sudo npm install -g npm;
  node --version;
}

This assumes you've already installed "n" from Eldar Djafarov's answer. After saving this to your Bash profile, re-open the terminal and just type update-node and enter your sudo password:

λ update-node
Password:
/usr/local/bin/npm -> /usr/local/lib/node_modules/npm/bin/npm-cli.js
/usr/local/bin/npx -> /usr/local/lib/node_modules/npm/bin/npx-cli.js
+ npm@5.3.0
updated 1 package in 7.232s
v8.2.1
What Would Be Cool
  • 4,551
  • 4
  • 42
  • 41
0

just run command line npm install -g npm or sudo npm install -g npmto update it for mac user. That's it.

seyha
  • 506
  • 5
  • 14
0

Windows 10

Open CMD in folder C:\Program Files\nodejs\node_modules and type npm i npm

Bill Zelenko
  • 1,586
  • 1
  • 12
  • 21
0

For Ubuntu

Install the nvm (Node Version Manager) using the below command

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

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

or Wget:

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

check if nvm is already installed

nvm --version

To install or update node, run below command:

nvm install 10.14.1(the version of node one want to install)

To check the list of node version available to the system or currently running for the system, run the below command:

nvm list

It will list all the available node version present in the system

check the node version:

node -v

Neha
  • 140
  • 5
0

If there is an issue with sudo/root access we can do

npm install stable Or
npm install 10.15.0
Rajendra Kadam
  • 3,491
  • 1
  • 8
  • 21
Rohit Parte
  • 1,568
  • 18
  • 13
0

Just install node js using nvm. It will download the lates version of node js.

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

after executing the command. close your terminal and reopen then run this command to install node js latest version.

run : nvm install v14.15.5

now check by typing node -v

-1

If Node install script doesn't work for you (it didn't for me), here's the solution to update Node Js in Debian Jessie, taken from the reply from Thomas Ward at askubuntu.com (Thanks, buddy!).

1.- Create a new file: /etc/apt/sources.list.d/nodesource.list

You'll need to create this file with sudo, but when you create the file, put this inside it:

deb https://deb.nodesource.com/node_9.x jessie main
deb-src https://deb.nodesource.com/node_9.x jessie main

Then, save the file. (replace node_9.x with the desired version)

2.- Download the GPG Signing Key from Nodesource for the repository. Otherwise, you may get NO_PUBKEY errors with apt-get update:

curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -

3.- Manually run sudo apt-get update.

This refreshes the data from the nodesource repo so apt knows a newer version exists.

If you get a NO_PUBKEY GPG error, then go back to Step 2

4.- Check apt-cache policy nodejs output.

This is not done by the script, but you want to make sure you see an entry that says something like this in the output:

Version table:
 *** 9.2.0-1nodesource1 0
        500 https://deb.nodesource.com/node_9.x/ jessie/main amd64 Packages
        100 /var/lib/dpkg/status
     0.10.29~dfsg-2 0
        500 http://ftp.debian.org/debian/ jessie/main amd64 Packages

If you do not see entries like this, and only see 0.10.29, start over. Otherwise, proceed.

5.- Install the nodejs binary. Now that you have confirmed 9.x is available on your system, you can install it: sudo apt-get install nodejs

nodejs -v should now show v9.2 or similar on output (as long as it starts with v9. you're on version 9 then).

moy2010
  • 358
  • 6
  • 11
-3

forget all of the above answer if its not working just run the following command if you have install nvm

nvm alias 12.16.0 //add your required node version