Sensible Setup of Node.js on Windows

  • Goal is to have a setup that works with native Windows/PowerShell and also WSL terminals
  • Use C:\Lib\Node.js to store Node.js
  • Node.js can easily be upgraded and default version changed seamlessly
  • Fast Node Manager (fnm) is the best way to install and manage Node.js on Windows

I like putting things like JVM and Android SDK in C:\Lib. Windows doesn’t have /lib or /usr/lib like in Linux. C:\Lib is a convenient place to keep libraries. It’s much easier to create an alias with a path in C:\Lib than e.g. C:\Program Files\…

Install fnm:

mkdir C:\Lib\Node.js  # may or may not require admin
winget install Schniz.fnm  # doesn't require admin

Configure PowerShell profile. This sets the default install directory to C:\Lib\Node.js:

vi $profile  # requires 'vi' to be installed and aliased
# Fast Node Manager
fnm env --fnm-dir C:\Lib\Node.js --use-on-cd | Out-String | Invoke-Expression

Create WSL .bashrc and/or .zshrc alias:

node() {
    /mnt/c/Lib/Node.js/aliases/default/node.exe $@
}

Close and restart PowerShell, then install LTS release of Node.js:

fnm install --lts  # doesn't require admin

In a PowerShell or in a WSL Bash/ZSH terminal you should now be able to type ‘node‘ and see:

Welcome to Node.js v20.15.1.
Type ".help" for more information.

Full list of fnm commands available here.