1232

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.

0

41 Answers 41

1870

Ubuntu Linux/Mac

The module n makes version management easy:

sudo npm install n -g

For the latest stable version:

n stable

For the latest version:

n latest

Debian 10 (Buster)

Upgrade older versions of Node.js and npm on Debian 10 as follows:

sudo su -c 'curl -sL https://deb.nodesource.com/setup_18.x | bash -'
sudo apt-get install nodejs -y
sudo apt update
sudo apt upgrade
sudo npm install -g [email protected]
node --version
npm --version

Note: Replace setup_18 with the latest long-term support release.

Windows

Just reinstall Node.js from the .msi file in Windows from the Node.js website.

Sign up to request clarification or add additional context in comments.

30 Comments

"npm install -g n" did it!
@ZenMaster just reinstall node from the .msi in Windows from the node website. No need for n
OSX Yosemite, npm install n -g && n stable worked for me. No need for sudo if node was not previously installed with it.
This answer is out of date. The best way to install/upgrade nodejs is to use Node Version Manager here: github.com/creationix/nvm or read this answer below
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.
|
840

All platforms (Mac, Linux, and Windows) 2024

If you just need to upgrade your old version of Node.js to the latest one and don't need multiple versions, simply overwrite your existing executable with the new one.

Download the latest Node.js from nodejs.org/en/download

Enter image description here

This just Works! TM on all platforms and is the easiest/fastest method.
When you run node -v in your terminal, you will see the the latest version.

Mac

If you originally installed Node.js using Homebrew, then run:

brew upgrade node

Managing multiple versions of Node.js

If you need to run multiple versions of Node.js on your machine, e.g., if you have an older project that targets a specific version on AWS Lambda, then NVM (Node Version Manger) is your friend!

Step 1 - Get NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

If you're curious about the installation command, read the source code. It’s been reviewed by several Node.js security experts.

Step 2 - Install the specific 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 v22.16.0

Note: you may need to close and reopen your terminal window for nvm command to be available.

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

Now using node v22.16.0

You now have the latest Node.js on your machine.
And if you need to temporarily switch to a different/previous version, you can do it with a simple nvm command.

Note: avoid using sudo with Node/NPM as it violates the security principle of least privilege.

NVM is considered better than N for managing multiple Node.js versions because the verbose commands mean it is much easier to keep track of what you are doing in your Terminal/SSH Log. It is used by the team at NPM, the creators/custodians of the Node.js world!

25 Comments

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.
None of them are supported in Windows. NVM suggests nvmw and nvm-windows that are "neither supported nor developed by" NVM and I havent testsed out yet. @nelsonic your answer is awesome
@redOctober13 sounds like you need to fix your permissions. see: github.com/nvm-sh/nvm/issues/1164#issuecomment-248749969 You should avoid using sudo (root access) wherever possible.
It's work on ubuntu 18.04 I got the latest version with: nvm install v12.6
STEP 2: Incase you get the error: "command not found: nvm" Run: source ~/.nvm/nvm.sh
|
153

Via npm:

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

And also you can specify a desired version:

n 0.8.21

In case it doesn't seem to work, the installation gives you a hint:

If "node --version" shows the old version then start a new shell, or reset the location hash with: hash -r (for bash, zsh, ash, dash, and ksh) [or] rehash (for csh and tcsh)

Reference

1 Comment

Whenever I run npm install -g n it's giving me "Unsupported platform for [email protected]" error.
80

All platforms (Windows, Mac, and Linux)

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

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.

8 Comments

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/
@gnB What kind of error did you get? I'll include it in the answer.
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
just downloaded newest version, install, went to command prompt typed node -v, saw change instantly.
Just adding for the less experienced ones, that after downloading the binary, there is a bit of installation process, as described here: medium.com/@tgmarinho/….
|
70

On Windows, download the latest "Windows Installer (.msi)" from Index of /download/release/latest/ and install the same directory. That’s all...

After completing the installation above, the Node.js and NPM will be upgraded to the latest one and then you can clean up the package as normal as:

npm cache clean
npm update -g

Note

You can always check the version with following command:

C:\node -v

Output:

v0.12.4

And:

C:\npm -version

Output:

2.10.1

2 Comments

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?
Now you should run npm cache verify not npm cache clean
44

Use the following to upgrade Node.js to the 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 the latest version:

sudo n latest

If you need to do undo, then follow the commands:

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

This method of upgrading Node.js 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 losing 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 the use:

nvm use 0.12

Addition n13: In case 'sudo n stable' has errors, try this:

sudo -E env "PATH=$PATH" n stable

3 Comments

This fixed my problem. Apparently, after updating the node needs a linking to the newer version
sudo n stable didn't work - it said 'cant find command n'. Solution to that from another SO posT: sudo -E env "PATH=$PATH" n stable
Please don't run sudo npm/n! It will mess up your permissions for several global npm packages and cause trouble the next time one of them is updated. See recent solutions in this thread.
26

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. It assumes you already have Node.js 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.js, 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.js on Windows with Chocolatey

cinst nodejs.install -Version 0.10.26

3 Comments

I had to run choco install nodejs.install for it to see my existing installation.
Make sure to run command prompt as administrator. (choco will warn you)
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!
18

In order to install the latest version of Node.js and npm, do the following:

nvm install --lts

Comments

17

Install npm

sudo apt-get install npm

Install n

sudo npm install n -g

Latest version of Node.js

sudo n latest

So the latest version will be downloaded and installed.

Specific version of Node.js you can

List available Node.js versions

n ls

Install a specific version

sudo n 4.5.0

Comments

15

For Homebrew users on Mac OS X

cd ~/dev/cookiecutter-ionic
brew upgrade node

Which produces:

==> 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

Comments

11

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

Comments

10

I had Node.js version v7.10.0 in Ubuntu.

I used the below commands to upgrade:

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

Now it’s upgraded to v8.2.1.

Or

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

# The below command should get the latest version of Node.js
node --version

# Install specific version of Node.js
n 8.2

# Check for the installed Node.js version
node --version

Comments

8

Using Homebrew and nvm on Mac OS X:

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

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.js 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.

Comments

8

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.

1 Comment

Simple but effective. Thanks.
7
brew upgrade node

will upgrade to the latest version of the Node.js.

Comments

6

It's very simple in the Windows OS.

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

Just go to nodejs.org.

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

It will download the latest Node.js and npm for you and discarding the old one.

Comments

6

I tried both with n and with nvm on Linux Ubuntu 12.04 LTS (Precise Pangolin), in order to update Node.js 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.

Comments

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. Go to Download Node.js.

1 Comment

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).
3

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

Comments

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.

Comments

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.

Comments

2

If you are looking in Linux...

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

The terminal process to upgrade Node.js 4.x to 6.x.

node -v

Output:

v4.x

Check the Node.js path

which node

Output:

/usr/bin/node

Download the latest (6.x) Node.js files from Download, unzip the files, and keep them in /opt/node-v6.9.2-linux-x64/.

Now unlink the current Node.js and link with the latest as in the following.

unlink /usr/bin/node
ln -s /opt/node-v6.9.2-linux-x64/bin/node node
node -v

Output:

v6.9.2

Comments

2

There is a good explanation for Linux users on how to update the Node.js version step by step.

PS: type instead of sudo n stable sudo n latest for receiving the latest Node.js version.

If you receive the following error,

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

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

Comments

2

For Windows users, simply go to the Node.js (nodejs.org) website and download the latest version (8.6.0 as of 2017-09-29).

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.

1 Comment

I'm unsure what this answer adds to the many already existing ones.
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

Comments

1

I am installing node for angular setup in Ubuntu. I also struggled a little bit. Here is the solution to save your time.

  1. Run the following commands

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -

  1. then run below code

sudo apt-get install -y nodejs

It should work, but if still didn't work to you let me know.

Comments

1

If you have npm installed, you can use nvm to change the Node.js package version locally. This can be done by running

npm i nvm

Then type:

nvm install 18.x

Note that the above will install Node.js version 18.x.

nvm use 18

This will change your local Node.js version to version 18. This is a quick way to swap between different versions of Node.js.

Comments

1

To upgrade Node.js to the latest version, you can follow these general steps:

Check the current version: First, check the currently installed version of Node.js by running:

node -v

Choose the installation method: Decide on the installation method. You can either use a package manager, like npm or Yarn, or you can download the Node.js installer directly from the Node.js website.

Using npm (Node Package Manager):

  • Open your terminal or command prompt.

  • Run the following command to update npm to the latest version (optional but recommended):

     npm install -g npm@latest
    

    Then, run the following command to upgrade Node.js:

     npm install -g node@latest
    

Using Yarn:

If you're using Yarn, you can upgrade Node.js by running:

yarn global upgrade node

Direct download:

Alternatively, you can visit the official Node.js website and download the latest installer for your operating system. Run the installer, and it should automatically replace the older version with the latest one.

Verify installation: After the installation is complete, verify that Node.js has been upgraded successfully by running:

node -v

Check npm Version: You might also want to check the npm version by running:

npm -v

Update global packages (optional): If you have global npm packages installed, you might want to update them to ensure compatibility with the new Node.js version. You can do this by running:

npm update -g

By following these steps, you should be able to upgrade Node.js to the latest version on your system. Remember to check compatibility with your existing projects and dependencies after the upgrade.

1 Comment

1

After installing 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.js version and keep the installed packages:

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

Comments

1

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 environment PATH and that’s it!

1 Comment

First make sure that you have npm installed 1. Run the following cmd curl -fsSL deb.nodesource.com/setup_16.x | sudo -E bash - 2. run below cmd sudo apt-get install -y nodejs

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.