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.
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
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!
Videos
How often should I upgrade Node.js?
How to upgrade Node.js to the latest version quickly?
How to verify the Node.js version after upgrade?
2026 Update: Use FNM
fnm is a fully Rust-based Node.js version manager and 10 times faster than nvm. It works on Windows, Mac, and Linux, unlike nvm
Check which version of fnm is installed
fnm --versionInstall a specific version of Node.js
fnm install 22.12.10Use a specific version of Node.js
fnm use 22.12.10Check out all the fnm commands here
Older answer with nvm
To upgrade Node.js, you may first want to see which version of Node.js you are currently using:
node --version
Find out which versions of Node.js you may have installed and which one of those you're currently using:
nvm ls
List all versions of Node.js available for installation:
nvm ls-remote
Apparently for Windows, the command would be rather like this:
nvm ls available
Assuming you would pick Node.js v8.1.0 for installation you'd type the following to install that version:
nvm install 8.1.0
You are then free to choose between installed versions of Node.js. So if you would need to use an older version like v4.2.0 you would set it as the active version like this:
nvm use 4.2
That should be all.
In 2013, I used the following instructions to upgrade from Node.js version 0.10.6 to 0.10.21 on a Mac, for more recent instructions see above.
Update from 2017: Please mind, Mr. Walsh himself recommended to update Node.js just using nvm instead.
Clear NPM's cache:
sudo npm cache clean -fInstall a little helper called 'n'
sudo npm install -g nInstall the latest stable Node.js version
sudo n stable
Alternatively, pick a specific version and install like this:
sudo n 0.8.20
For production environments, you might want to pay attention to version numbering and be picky about odd/even numbers.
Credits
- General procedure: D.Walsh
- Stable/unstable versions: P.Teixeira
Use Node Version Manager (NVM)
It's a Bash script that lets you download and manage different versions of node. Full source code is here.
There is a separate project for nvm for Windows: github.com/coreybutler/nvm-windows
Below are the full steps to use NVM for multiple version of node on windows
- download nvm-setup.zip extract and install it.
- execute command
nvm list availablefrom cmd or gitbash or powershell, this will list all available version of node - use command
nvm install versione.g.nvm install 12.14.0to install on the machine - last once installed use
nvm use versionto use newer version e.g.nvm use 12.14.0
Use n module from npm in order to upgrade node
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
To upgrade to latest version (and not current stable) version, you can use
sudo n latest
Fix PATH:
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/nodeTo undo:
sudo n rm 6.0.0 # replace number with version of Node that was installed sudo npm uninstall -g n
You may need to restart your terminal to see the updated node version.
Found in David Walsh blog
NodeSource provides binary distributions of Node.js; complete installation instructions can be found here. The instructions have been copied below for your reference. Instructions are the same for updating to the latest version.
Run once:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
Run whenever you want to change the major version of Node.js:
NODE_MAJOR=20
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
sudo apt-get update
sudo apt-get install nodejs -y
Prior to August 2023: Previously versions of this answer involved the use of a series of setup_XX.x scripts that you'd run to install/update Node.js:
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
sudo apt-get install -y nodejs
But as @eis pointed out, these scripts are no longer supported. To see the previous answers, please look at the edit history for this answer.