Skip to content

Install fnm on Windows

fnm provides multiple installation methods on Windows. This guide will help you choose the most suitable method.

Installation Methods

winget is the package manager built into Windows 11 and Windows 10 (1809+):

powershell
winget install Schniz.fnm

Using Scoop

Scoop is a popular command-line package manager on Windows:

powershell
# Install Scoop (if not already installed)
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex

# Install fnm
scoop install fnm

Using Chocolatey

Chocolatey is a widely used package manager on Windows:

powershell
# Install Chocolatey (if not already installed)
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

# Install fnm
choco install fnm

Using Installation Script

In Git Bash or WSL:

bash
curl -fsSL https://fnm.vercel.app/install | bash

Manual Download

  1. Visit fnm Releases page
  2. Download fnm-windows.zip
  3. Extract to target directory
  4. Add the extracted directory to system PATH

Configure PowerShell

After installation, you need to configure the PowerShell environment.

Automatic Configuration

Run the following command to add fnm configuration to PowerShell profile:

powershell
# Create profile (if it doesn't exist)
if (!(Test-Path -Path $PROFILE)) {
    New-Item -ItemType File -Path $PROFILE -Force
}

# Add fnm configuration
Add-Content -Path $PROFILE -Value 'fnm env --use-on-cd | Out-String | Invoke-Expression'

# Reload configuration
. $PROFILE

Manual Configuration

  1. Open PowerShell profile:
powershell
notepad $PROFILE
  1. Add the following content:
powershell
fnm env --use-on-cd | Out-String | Invoke-Expression
  1. Save and reload:
powershell
. $PROFILE

Configure VS Code

If you use VS Code, you need to configure the integrated terminal:

  1. Open Settings (Ctrl + ,)
  2. Search for terminal.integrated.profiles.windows
  3. Add or modify PowerShell configuration:
json
{
  "terminal.integrated.profiles.windows": {
    "PowerShell": {
      "source": "PowerShell",
      "args": ["-NoLogo"]
    }
  }
}

Using Mirror in China

In mainland China, it's recommended to configure a mirror to accelerate downloads:

powershell
# Set environment variable
[Environment]::SetEnvironmentVariable("FNM_NODE_DIST_MIRROR", "https://npmmirror.com/mirrors/node", "User")

# Or add to PowerShell profile
$env:FNM_NODE_DIST_MIRROR = "https://npmmirror.com/mirrors/node"
fnm env --use-on-cd | Out-String | Invoke-Expression

Verify Installation

powershell
# Check fnm version
fnm --version

# Install Node.js
fnm install --lts

# Verify Node.js
node --version
npm --version

Shell Completion

Enable PowerShell command completion:

powershell
# Add completion script to profile
fnm completions --shell powershell | Out-String | Add-Content $PROFILE

# Reload configuration
. $PROFILE

Common Issues

Command Not Found

If fnm command is not found after installation:

  1. Confirm fnm is added to PATH
  2. Reopen PowerShell window
  3. Check installation path:
powershell
where.exe fnm

Execution Policy Error

If you encounter execution policy error:

powershell
# Allow running scripts
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Environment Variables Not Taking Effect

Ensure PowerShell profile is loaded correctly:

powershell
# Check profile path
$PROFILE

# Check profile content
Get-Content $PROFILE

# Manually reload
. $PROFILE

Using fnm in WSL

If you use fnm in WSL:

bash
# Install in WSL
curl -fsSL https://fnm.vercel.app/install | bash

# Configure Bash
echo 'eval "$(fnm env --use-on-cd)"' >> ~/.bashrc
source ~/.bashrc

Next Steps

After installation, you can: