How to Upgrade Node.js on Different Operating Systems
Step-by-Step Guide to Updating Node.js on Windows, macOS, and Linux for Optimal Performance and Security
Node.js, a popular JavaScript runtime, regularly releases updates to improve performance, fix bugs, and add new features. Staying up-to-date ensures compatibility with new libraries and keeps your system secure. Here’s a step-by-step guide on how to upgrade Node.js on Windows, macOS, and Linux.
1. Upgrade Node.js on Windows
Method 1: Using the Node.js Installer
Visit the official Node.js website.
Download the latest version for Windows (LTS or Current, depending on your needs).
Run the installer:
Follow the installation wizard.
It will automatically upgrade your existing Node.js version.
Method 2: Using nvm-windows
(Node Version Manager for Windows)
Download nvm-windows from the release page.
Install it and ensure it's added to your PATH.
Open a new Command Prompt or PowerShell window and run:
2. Upgrade Node.js on macOS
Method 1: Using Homebrew
Open Terminal.
Run the following commands:
brew update brew upgrade node
Verify the version:
node -v
Method 2: Using n
Install
n
(a version manager) globally if it’s not already installed:npm install -g n
Use
n
to install the latest version:n latest
Verify the version:
node -v
3. Upgrade Node.js on Linux
Method 1: Using NodeSource Repository (Debian/Ubuntu)
Open Terminal.
Add the NodeSource repository:
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -
Install or upgrade Node.js:
sudo apt-get install -y nodejs
Verify the installation:
node -v
Method 2: Using n
(for all Linux distros)
Install
n
globally:npm install -g n
Use
n
to install the latest version:sudo n latest
Check the installed version:
node -v
Method 3: Using nvm
(Node Version Manager)
Install or update
nvm
by running:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Restart your terminal or run:
source ~/.bashrc
Install the latest Node.js version:
nvm install node nvm use node
Verify:
node -v