Introduction to Node.js Version Management
Managing multiple Node.js versions can be challenging for developers who work on different projects with varying runtime requirements. While traditional installers limit you to a single Node.js version, Fast Node Manager (fnm) provides a flexible, efficient solution for switching between Node.js versions seamlessly.
What is fnm?
fnm is a fast and simple Node.js manager built in Rust β‘
Why Use fnm?
Before diving into the installation and usage, let's understand the advantages of fnm:
- Quick Version Switching: Instantly change Node.js versions without complex uninstallation processes.
- Project-Specific Configurations: Set different Node.js versions for different projects.
- Lightweight and Fast: Unlike some other version managers, fnm is designed to be minimal and performant.
- Cross-Platform Support: Works consistently across Windows, macOS, and Linux.
Step-by-Step Guide to Installing fnm
1. Installation Methods
For macOS and Linux:
# Using curl
curl -fsSL https://fnm.vercel.app/install | bash
# Alternative method using shell script
wget -qO- https://fnm.vercel.app/install | bash
For Windows:
# Using winget
winget install Schniz.fnm
# Using scoop
scoop install fnm
eval "$(fnm env --use-on-cd)"
2. PowerShell Configurations
Add the following to the end of your PowerShell profile file :
fnm env --use-on-cd --shell powershell | Out-String | Invoke-Expression
Note
You have to find the Powershell Profile file or create one if it's not already present, you can find the instructions below
For macOS/Linux, the profile is located at
~/.config/powershell/Microsoft.PowerShell_profile.ps1
For Windows location is either:
%userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Powershell 5
%userprofile%\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
If the profile is not present and to create the profile file you can run this in PowerShell:
if (-not (Test-Path $profile)) { New-Item $profile -Force }
To edit your profile run this in PowerShell:
Invoke-Item $profile
Invoke it and then add the first PowerShell command to the end of your PowerShell Profile
This enables automatic Node.js version switching and you can easily use multiple node js versions.
Basic fnm setup flow
# Download and install fnm:
winget install Schniz.fnm
# Download and install Node.js:
fnm install 22
# Select the version
fnm use 22
# Verify the Node.js version:
node -v # Should print "v22.13.1".
# Verify npm version:
npm -v # Should print "10.9.2".
If you face any error such as "can't find fnm's environment variables", then it may be related to configurations of the shell you are using!
Installing Node.js Versions
# Install the latest LTS version
fnm install --lts
fnm i --lts
# Install a specific version
fnm install 16.14.2
# Install the latest version
fnm install latest
Managing Installed Versions
# List all installed Node.js versions
fnm ls
# List all remote Node.js versions
fnm ls-remote
# Set a default global Node.js version
fnm default 22.13.1
# Use a specific version in the current shell
fnm use 22.13.1
Current Node Version
fnm current
Version Aliasing
# Syntax to set an alias for a version is
fnm alias <version> <name>
fnm alias 22.13.1 my-nodeproject
# Use the aliased version
fnm use my-nodeproject
# To set the default alias
fnm default 22.13.1
# To Unalias
fnm unalias <name>
fnm unalias my-nodeproject
Project-Specific Version Management
Create a .node-version
file in your project root to automatically use a specific Node.js version:
# In your project directory
echo "22.13.1" > .node-version
Now, when you enter the project directory, fnm will automatically switch to the specified version.
Best Practices
- Always use LTS (Long Term Support) versions for production projects.
- Regularly update fnm to get the latest features and improvements.
- Use
.node-version
or.nvmrc
files to maintain consistency across development teams.
Troubleshooting
Again, If you encounter issues:
- Ensure fnm is correctly added to your PATH
- Verify shell configuration
- Check fnm version with
fnm --version
Conclusion
Fast Node Manager simplifies Node.js version management, offering developers a flexible, efficient tool for handling multiple runtime environments. By following these steps, you can easily switch between Node.js versions and maintain project-specific configurations.
If you liked this article, drop a like or comment ** β€ or **maybe share it in your community :). You can also drop me a follow on X π€ or Linked In π¨βπ«
Top comments (0)