Install fnm on macOS
fnm has multiple installation methods on macOS. This guide will help you choose the most suitable method.
Installation Methods
Using Homebrew (Recommended)
Homebrew is the most popular package manager on macOS:
bash
# Install fnm
brew install fnmUsing curl Script
No package manager required, install directly:
bash
curl -fsSL https://fnm.vercel.app/install | bashUsing MacPorts
If you use MacPorts:
bash
port install fnmManual Download
- Visit fnm Releases page
- Download
fnm-macos.zip(Intel) orfnm-macos-arm64.zip(Apple Silicon) - 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/binConfigure 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 ~/.zshrcBash
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_profileFish
Edit ~/.config/fish/config.fish:
fish
# Open configuration file
nano ~/.config/fish/config.fish
# Add the following content
fnm env --use-on-c | sourceReload configuration:
fish
source ~/.config/fish/config.fishShell 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 && compinitOr 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/_fnmBash Completion
bash
# Add completion script
fnm completions --shell bash >> ~/.bashrc
# Reload
source ~/.bashrcFish Completion
bash
# Generate completion script
fnm completions --shell fish > ~/.config/fish/completions/fnm.fish
# Reload
source ~/.config/fish/config.fishUsing 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=x64Verify Installation
bash
# Check fnm version
fnm --version
# Install Node.js
fnm install --lts
# Verify Node.js
node --version
npm --versionCommon 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/fnmHomebrew Installation Not Working
bash
# Re-link
brew unlink fnm && brew link fnm
# Check installation
brew list fnmNext Steps
After installation, you can:
- Install Node.js - Use fnm to install Node.js
- Command Reference - Learn all available commands
- Version Management - Learn version management
Related Links
- Install fnm - General installation guide
- Windows Installation - Windows installation guide
- Linux Installation - Linux installation guide