To update Node.js on your system, follow the guide based on your environment:
Updating Node.js on Linux (including Ubuntu/Mint)
Using Node Version Manager (NVM)
This is the most flexible and recommended method, as it allows you to have multiple versions of Node.js installed and switch between them.
Installing NVM:
Open the terminal.
Run the command to install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- After installation, reload the terminal environment:
source ~/.bashrc
Check if NVM was installed correctly:
nvm --version
Installing the latest version of Node.js:
- Use the following command to list the available Node.js versions:
nvm ls-remote
- To install the latest version of Node.js:
nvm install node
Or if you want a specific version, replace node
with the desired version, for example:
nvm install 16.20.1
Setting a default version:
After installing the desired version, you can set it as the default:
nvm use 16.20.1
nvm alias default 16.20.1
Using official repositories (if you don't want to use NVM)
- Add the NodeSource repository:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
replace setup_lts.x
with setup_18.x
or setup_20.x
for specific versions
- Install Node.js:
sudo apt install -y nodejs
- Check if Node was updated:
node -v
Updating on Windows (with or without NVM-Windows)
Using NVM-Windows
Download and install NVM for Windows.
After installation, use the terminal:
nvm install latest
- Set the version as default:
nvm use latest
Using the Node.js Installer
Go to the official Node.js website: nodejs.org.
Download the latest version (LTS recommended).
Run the installer and follow the instructions.
Updating on macOS
Using NVM (Node Version Manager)
- Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- Activate NVM
source ~/.bashrc
or, if you're using zsh
, use:
source ~/.zshrc
- Verify the installation
nvm --version
- Install or update Node.js
nvm install node
Or, if you prefer a specific version:
nvm install 18.17.1
- Set the default version
nvm alias default 18.17.1
- Check the Node.js version
node -v
Using Homebrew
- Update Homebrew
brew update
- Update Node.js
brew upgrade node
- Install Node.js (if not installed)
brew install node
- Check the installed version
node -v
Using the Node.js Installer
If you prefer a simple method, you can use the official installer:
Go to the official Node.js website.
Download the latest version (LTS is recommended).
Follow the installer instructions to update Node.js.