You are probably here because you tried to run npm install and got a warning about your Node.js version being outdated, or maybe you want to try out the latest features in the new release. Updating Node.js can sometimes feel risky—no one wants to break their working environment with a sudden version mismatch.
Don't worry. Whether you are using Windows, macOS, or Linux, there is a safe way to update without breaking your projects. In this guide, we will cover the most reliable methods to get the latest LTS (Long Term Support) version, starting with the methods developers actually use.
Check Your Current Node.js and NPM Version
Before making any changes, it is smart to know exactly what you are running. Open your terminal (or Command Prompt on Windows) and type:
node -v
npm -vIf you see something like v14.x.x, it is definitely time to upgrade. Older versions no longer receive security updates. Knowing your current path is also useful; if you need to locate where Node is installed, you might want to learn how to find a directory on Linux or macOS to check your installation folder.
Method 1: Using NVM (Recommended for All Users)
This is the gold standard for managing Node.js. NVM (Node Version Manager) allows you to install multiple versions side-by-side and switch between them instantly. This prevents permission errors and ensures you never break a project that relies on an older version.
For macOS and Linux Users
If you haven't installed NVM yet, you can grab it with a simple curl command. Once installed, updating is incredibly fast.
- Check for available versions:
nvm ls-remoteInstall the latest LTS version:
nvm install --ltsUse the new version:
nvm use --ltsIf you want to set this as your default so you don't have to switch every time you open a new terminal:
nvm alias default <version_number>For Windows Users (nvm-windows)
Standard NVM doesn't work on Windows, but there is a fantastic alternative called nvm-windows.
- Download the latest installer from the nvm-windows GitHub release page.
- Run the installer. It will automatically detect your existing Node.js installation.
- Open PowerShell (run as Administrator) and type:
nvm install lts
nvm use ltsIf you are writing scripts to automate this and need to debug the process, knowing how to pause in PowerShell can be helpful to see the output before the window closes.
Method 2: Using the 'n' Package (macOS & Linux Only)
If you find NVM too complex and just want a quick update command, the n package is your best friend. It is an interactive Node.js version manager that is extremely easy to use.
Note: You cannot use this on Windows directly.
Clear your npm cache to avoid conflicts:
npm cache clean -fInstall 'n' globally:
sudo npm install -g nUpdate to the stable version:
sudo n stableYou can also use sudo n latest for the absolute newest features. If you previously installed Node via a different method and this doesn't work, you might need to manually remove directory in Linux related to the old installation to prevent conflicts.
Method 3: Using Package Managers (Homebrew & Chocolatey)
If you prefer managing all your software from one place, system package managers are a solid choice.
macOS with Homebrew
If you installed Node.js via Homebrew, updating is straightforward:
brew update
brew upgrade nodeWindows with Chocolatey
Chocolatey is a lifesaver for Windows developers. To update Node.js:
choco upgrade nodejsWindows with Scoop
If you use Scoop:
scoop update nodejsMethod 4: The Official Installer (Windows & macOS)
We list this last because it is the least flexible method. While downloading the installer from the official Node.js website works, it replaces your current version entirely. You can't easily switch back if something goes wrong.
- Go to the official Node.js website.
- Download the LTS installer for your OS.
- Run the wizard and follow the steps.
Pro Tip: If you choose this method on Windows, ensure the installer adds Node to your PATH correctly. If your terminal still shows the old version after installation, you may need to learn how to use environment variables to fix your system PATH manually.
How to Update NPM (Node Package Manager)
Sometimes you don't need a new Node.js version, just a newer npm. Interestingly, npm is a separate package and updates independently.
To update npm to the latest version:
npm install -g npm@latestThis installs the newest npm globally.
Troubleshooting Common Update Errors
Permission Denied (EACCES) This usually happens when you try to install global packages without the right permissions. Using NVM typically solves this permanently. If you are stuck on Linux, avoid using sudo for every npm command; instead, fix your directory permissions.
Version Not Changing If you installed the new version but node -v still shows the old one, your system PATH is likely pointing to the wrong location. Check your environment variables or restart your terminal.
Comments (0)
Sign in to comment
Report