fnm Command Reference
fnm provides a concise and powerful set of command-line tools to manage Node.js versions.
Command Overview
fnm [OPTIONS] <COMMAND>Global Options
| Option | Description | Default |
|---|---|---|
--node-dist-mirror <URL> | Node.js download mirror | https://nodejs.org/dist |
--fnm-dir <DIR> | fnm installation directory | ~/.fnm |
--log-level <LEVEL> | Log level | info |
--arch <ARCH> | Architecture override | System architecture |
--version-file-strategy <STRATEGY> | Version file parsing strategy | local |
--corepack-enabled | Enable Corepack | false |
--resolve-engines | Resolve engines.node in package.json | true |
Core Commands
fnm install
Install new Node.js versions.
fnm install [OPTIONS] [VERSION]Parameters:
VERSION- Version number, can be partial semver or LTS version name (e.g.,lts/iron)
Options:
--lts- Install latest LTS version--latest- Install latest version--use- Use the version immediately after installation--progress <auto|never|always>- Display download progress bar
Examples:
# fnm version
fnm --version
# Install latest LTS version
fnm install --lts
# Install latest version
fnm install --latest
# Install specific version
fnm install 20
fnm install 18.17.0
# Install specific LTS version
fnm install lts/iron
# Install and use immediately
fnm install 20 --usefnm use
Switch Node.js version.
fnm use [OPTIONS] [VERSION]Options:
--install-if-missing- Automatically install if version is not installed--silent-if-unchanged- Do not output message if version is unchanged
Examples:
# Use specific version
fnm use 20
# Use latest installed version
fnm use
# Auto install if not installed
fnm use 18 --install-if-missingfnm list
List locally installed Node.js versions.
fnm list [OPTIONS]Alias: ls
Example:
fnm listOutput example:
* v20.10.0 default
v18.19.0
v16.20.2fnm list-remote
List all available remote Node.js versions.
fnm list-remote [OPTIONS]Alias: ls-remote
Options:
--filter <FILTER>- Filter by version number or semver range--lts [<NAME>]- Show only LTS versions--latest- Show only latest versions--sort <asc|desc>- Sort order
Examples:
# List all versions
fnm list-remote
# List only LTS versions
fnm list-remote --lts
# List specific LTS version
fnm list-remote --lts=iron
# Filter versions
fnm list-remote --filter=18
# Show only latest versions
fnm list-remote --latestfnm uninstall
Uninstall Node.js version.
fnm uninstall [OPTIONS] [VERSION]Alias: uni
Examples:
# Uninstall specific version
fnm uninstall 16.20.2
# Uninstall via alias
fnm uninstall defaultWARNING
If an alias is provided, fnm will delete the Node.js version that alias points to, as well as other aliases pointing to the same version.
Version Management Commands
fnm default
Set or get the default Node.js version.
fnm default [VERSION]Examples:
# Set default version
fnm default 20
# Get current default version
fnm defaultfnm current
Display the currently used Node.js version.
fnm currentExample:
fnm current
# Output: v20.10.0fnm alias
Set an alias for a version.
fnm alias <VERSION> <NAME>Examples:
# Set alias
fnm alias 20 default
fnm alias 18 legacy
# Use alias
fnm use defaultfnm unalias
Delete an alias.
fnm unalias <NAME>Example:
fnm unalias legacyEnvironment Configuration Commands
fnm env
Output Shell environment variable configuration.
fnm env [OPTIONS]Options:
--shell <bash|zsh|fish|powershell>- Specify Shell type--json- Output in JSON format--use-on-cd- Output auto version switching script
Examples:
# Output current Shell configuration
fnm env
# Output Bash configuration
fnm env --shell bash
# Output JSON format
fnm env --json
# Enable auto version switching
fnm env --use-on-cdfnm completions
Output Shell completion script.
fnm completions [OPTIONS]Options:
--shell <bash|zsh|fish|powershell>- Specify Shell type
Examples:
# Bash
fnm completions --shell bash >> ~/.bashrc
# Zsh
fnm completions --shell zsh >> ~/.zshrc
# Fish
fnm completions --shell fish > ~/.config/fish/completions/fnm.fish
# PowerShell
fnm completions --shell powershell >> $PROFILEAdvanced Commands
fnm exec
Execute a command in a specified Node.js version environment.
fnm exec [OPTIONS] -- <COMMAND>Options:
--using <VERSION>- Specify the version to use
Examples:
# Execute command using Node.js 18
fnm exec --using=18 -- node --version
# Run script using specific version
fnm exec --using=20 -- npm run buildCommand Cheat Sheet
| Command | Alias | Description |
|---|---|---|
install | i | Install Node.js version |
use | - | Switch Node.js version |
list | ls | List installed versions |
list-remote | ls-remote | List remote versions |
uninstall | uni | Uninstall Node.js version |
default | - | Set/get default version |
current | - | Show current version |
alias | - | Set version alias |
unalias | - | Delete alias |
env | - | Output environment configuration |
completions | - | Output completion script |
exec | - | Execute command in specified version |
Related Links
- Install Node.js - Detailed installation guide
- Version Management - Version management best practices
- install Command - install command detailed explanation