Skip to content

fnm use Command Guide

The fnm use command is used to switch the currently used Node.js version.

Command Syntax

bash
fnm use [OPTIONS] [VERSION]

Parameters

VERSION

Specify the Node.js version to switch to:

bash
# Switch to major version
fnm use 20

# Switch to specific version
fnm use 20.10.0

# Use alias
fnm use default

# No version specified, reads from version file
fnm use

Options

--install-if-missing

Automatically install the version if not already installed:

bash
fnm use 18 --install-if-missing

--silent-if-unchanged

Do not output message if version is unchanged:

bash
fnm use 20 --silent-if-unchanged

--node-dist-mirror

Used with --install-if-missing to specify download mirror:

bash
fnm use 18 --install-if-missing --node-dist-mirror=https://npmmirror.com/mirrors/node

--fnm-dir

Specify fnm installation directory:

bash
fnm use 20 --fnm-dir=/custom/path

--log-level

Set log level:

bash
fnm use 20 --log-level=quiet

Usage Examples

Basic Switch

bash
# Switch to Node.js 20
fnm use 20

# Switch to Node.js 18.17.0
fnm use 18.17.0

Auto Install and Switch

bash
# Automatically install if version is not installed
fnm use 16 --install-if-missing

Switch Using Alias

bash
# Use preset alias
fnm use default
fnm use legacy

Silent Mode

bash
# Use in scripts to avoid unnecessary output
fnm use 20 --silent-if-unchanged

Version Selection Priority

When no version is specified, fnm searches in the following order:

  1. .node-version file
  2. .nvmrc file
  3. package.json engines.node
  4. Default version

Difference from default Command

  • fnm use - Switches version for current Shell session
  • fnm default - Sets global default version
bash
# Set default version (affects new terminals)
fnm default 20

# Temporarily switch version (current terminal only)
fnm use 18

Common Issues

Version Not Installed

bash
# Error message
error: Can't find version 18.0.0

# Solution: Auto install
fnm use 18 --install-if-missing

node Version Doesn't Change After Switch

Ensure Shell configuration is correct:

bash
# Check node path
which node

# Should point to fnm directory
# ~/.fnm/node-versions/.../bin/node

Version File Not Working

bash
# Confirm --use-on-cd is enabled
eval "$(fnm env --use-on-cd)"

# Confirm version file exists
cat .node-version