Install Node.js on Windows via CLI (winget)
Setting up Node.js on Windows no longer requires clicking through installers — thanks to winget, Microsoft’s official Windows Package Manager.
Here’s how you can install Node.js with npm in seconds, entirely from the terminal.
1. Open PowerShell
Press Win + X → select Windows PowerShell (Admin) or Terminal (Admin).
2. Find Available Node.js Versions
First, list all available Node.js packages:
winget search OpenJS.NodeJS
You'll see results like:
Name Id Version
-----------------------------------------------
Node.js OpenJS.NodeJS 25.1.0
Node.js 14 OpenJS.NodeJS.14 14.18.1
Node.js 16 OpenJS.NodeJS.16 16.20.2
Node.js 18 OpenJS.NodeJS.18 18.20.8
Node.js 20 OpenJS.NodeJS.20 20.19.5
Node.js 21 OpenJS.NodeJS.21 21.7.2
Node.js 22 OpenJS.NodeJS.22 22.21.0
Node.js 23 OpenJS.NodeJS.23 23.11.0
Node.js (LTS) OpenJS.NodeJS.LTS 24.11.0
Pick the LTS version (recommended) or the latest version and install it:
winget install -e --id OpenJS.NodeJS.LTS
Or install the latest version:
winget install -e --id OpenJS.NodeJS
⚠️ The LTS (Long Term Support) version is recommended for most users — it's more stable and receives security updates longer.
3. Reopen Your CLI (Important!)
After installation, close and reopen PowerShell or Terminal. This refreshes the PATH so that node and npm are recognized.
Then verify the installation:
node --version
npm --version
You should see version numbers for both Node.js and npm (npm comes bundled with Node.js).
4. Troubleshooting: npm Not Recognized in PowerShell
If you see an error like npm : File C:\Program Files\nodejs\npm.ps1 cannot be loaded because running scripts is disabled on this system, PowerShell's execution policy is blocking npm scripts.
Here are three ways to fix it:
Option A: Change Execution Policy (Recommended)
Run PowerShell as Administrator and set the execution policy:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Then close and reopen PowerShell. This allows local scripts (like npm) to run while still protecting against unsigned remote scripts.
Option B: Use Command Prompt Instead
If you prefer not to change PowerShell settings, use Command Prompt (cmd) or Windows Terminal with the Command Prompt profile instead. npm works without any policy changes in cmd.
Option C: Bypass for Current Session
Temporarily bypass the policy for the current PowerShell session:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
This only affects the current session and resets when you close PowerShell.
5. (Optional) Upgrade npm
Keep npm up to date:
npm install -g npm@latest
Why Use winget?
✅ Official (maintained by Microsoft + OpenJS Foundation)
✅ Adds Node.js and npm to PATH automatically (just reopen your terminal to apply)
✅ Fully scriptable (great for automation & CI)
✅ Reproducible setup for fresh machines
That's it — you've installed Node.js and npm on Windows with a single command, and it's ready to use after reopening your terminal.
Top comments (0)