Skip to content

Install fnm on macOS

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

Installation Methods

Homebrew is the most popular package manager on macOS:

bash
# Install fnm
brew install fnm

Using curl Script

No package manager required, install directly:

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

Using MacPorts

If you use MacPorts:

bash
port install fnm

Manual Download

  1. Visit fnm Releases page
  2. Download fnm-macos.zip (Intel) or fnm-macos-arm64.zip (Apple Silicon)
  3. Extract and move to PATH directory:
bash
# Apple Silicon (M1/M2/M3)
unzip fnm-macos-arm64.zip
sudo mv fnm /usr/local/bin

# Intel Mac
unzip fnm-macos.zip
sudo mv fnm /usr/local/bin

Configure Shell

macOS defaults to Zsh, but also supports Bash and Fish.

Zsh (Default)

Edit ~/.zshrc:

bash
# Open configuration file
nano ~/.zshrc

# Add the following content
eval "$(fnm env --use-on-cd)"

Reload configuration:

bash
source ~/.zshrc

Bash

Edit ~/.bashrc or ~/.bash_profile:

bash
# Open configuration file
nano ~/.bash_profile

# Add the following content
eval "$(fnm env --use-on-cd)"

Reload configuration:

bash
source ~/.bash_profile

Fish

Edit ~/.config/fish/config.fish:

fish
# Open configuration file
nano ~/.config/fish/config.fish

# Add the following content
fnm env --use-on-c | source

Reload configuration:

fish
source ~/.config/fish/config.fish

Shell Completion

Zsh Completion

bash
# Add completion script
fnm completions --shell zsh > ~/.zsh/completion/_fnm

# Ensure fpath includes completion directory
# Add to ~/.zshrc
fpath=(~/.zsh/completion $fpath)

# Enable completion
autoload -U compinit && compinit

Or using oh-my-zsh:

bash
# Create completion directory
mkdir -p ~/.oh-my-zsh/completions

# Generate completion script
fnm completions --shell zsh > ~/.oh-my-zsh/completions/_fnm

Bash Completion

bash
# Add completion script
fnm completions --shell bash >> ~/.bashrc

# Reload
source ~/.bashrc

Fish Completion

bash
# Generate completion script
fnm completions --shell fish > ~/.config/fish/completions/fnm.fish

# Reload
source ~/.config/fish/config.fish

Using Mirror in China

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

bash
# Add to Shell configuration file
export FNM_NODE_DIST_MIRROR=https://npmmirror.com/mirrors/node

# Or specify during eval
eval "$(fnm env --use-on-cd --node-dist-mirror=https://npmmirror.com/mirrors/node)"

Apple Silicon (M1/M2/M3) Notes

fnm fully supports Apple Silicon:

  • Automatically detects system architecture
  • Installs native ARM64 version of Node.js
  • Supports x64 emulation (via Rosetta 2)

Install x64 Version

If you need the x64 version of Node.js:

bash
# Install x64 architecture Node.js
fnm install 20 --arch=x64

Verify Installation

bash
# Check fnm version
fnm --version

# Install Node.js
fnm install --lts

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

Common Issues

Command Not Found

If fnm command is not found after installation:

bash
# Check fnm path
which fnm

# If installed via curl, ensure PATH includes
echo $PATH

# Manually add to PATH
export PATH="$HOME/.fnm:$PATH"

Permission Issues

If you encounter permission issues:

bash
# Ensure directory has correct permissions
chmod +x ~/.fnm/fnm

Homebrew Installation Not Working

bash
# Re-link
brew unlink fnm && brew link fnm

# Check installation
brew list fnm

Next Steps

After installation, you can: