Photo by Gabriel Heinzer on Unsplash
Unleashing the Power of fnm: Your Ultimate Node Version Manager 🚀
Table of contents
- Installation for Linux system and zsh shell
- Getting Started with fnm - A Rust-Built Node.js Version Manager
- What is fnm, and why you should use it?
- Installing fnm
- Managing Node.js versions with fnm
- Listing all Node.js versions
- Using a particular version of Node.js
- Uninstalling Node.js versions
- Setting Node.js version aliases
- Uninstalling fnm
- Alternatives to fnm
- Conclusion
So, you've been tussling with Node.js for a while now, and what's the buzz? You've got projects scattered across different Node versions like a messy trail of breadcrumbs. The result? Chaos and confusion. But worry not, my fellow coder. Today, we're introducing you to the ultimate Node version manager – fnm, short for Fast Node Manager.
Installation for Linux system and zsh shell
Let's dive right in, shall we? First things first, let's get this gem installed. We'll focus on Linux systems and the zsh shell for now. For other platforms and shells, consult the documentation.
Shell setup: Open your
.zshrc
file and add the following line:export PATH=/home/$USER/.fnm:$PATH eval "$(fnm env --use-on-cd --version-file-strategy=recursive)"
Installing the completion script (optional but nifty): This little trick automagically completes your
fnm
commands. Paste the code below into a file named_fnm
in a directory specified in theFPATH
environment variable:fnm completions --shell zsh > <a_fpath_dir>/_fnm
Don't forget to replace
<a_fpath_dir>
with an actual directory.
Getting Started with fnm - A Rust-Built Node.js Version Manager
In the web development industry, Node.js is a household name. This is because it powers everything from video streaming on Netflix to helping astronauts stay safe in space. 🌐🚀
When it comes to installing Node.js on a development machine, you would normally install the environment using these steps:
First, navigate to the Node.js website and procure the latest LTS version:
The installation process differs across different OSes. For example, if you’re on Windows or macOS, run the executable installer. Alternatively, if you’re on Linux, use NodeSource to install Node on your machine:
As time goes on, you also have to manually check whether an update is available. If this is true, you would have to uninstall the previous version of Node and perform this process all over again.
You might think to yourself, “Sure, this process works for me.” However, there is a minor flaw in this process: it is too tedious and time-consuming. This is because of the following reasons:
Node.js doesn’t notify users when an update is available, which means that the developer has to regularly check for updates.
Furthermore, every time an update is available, you have to reinstall Node all over again, which wastes time and energy.
Finally, you can’t install different versions of Node on one computer. This is problematic in situations where, for example, a certain project relies on Node v16 and another app uses Node v18.
This is where fnm comes in. It is a piece of software written in Rust that allows developers to switch between Node versions with relative ease. 🦀
What is fnm, and why you should use it?
fnm, or Fast Node Manager, is a Node version manager that was written in Rust. Since it is a version manager, it boasts the easy installation of different Node.js versions. You can install Node via the install command: 🚀🔥
fnm install <version>
Other than that, uninstalling is a breeze. For example, we can remove different Node versions using the uninstall command:
fnm uninstall <version> #uninstall a version of Node.js
fnm uninstall 19.3.0 #use this version of Node.js
Moreover, this project is written in Rust. This means that fnm brings speed and stability to the table. 💨🛠️
Installing fnm
The fnm team bundles an installation script that makes downloading the software a breeze. To run this script, type this command in your terminal:
curl -fsSL https://fnm.vercel.app/install | bash
Don’t want to use the terminal? No problem! Head over to the Releases page and install their binaries. 💻🌐
When that’s done, verify that everything works by writing this bash command:
fnm --help
This should return this result:
This means that our installation was successful! In the next section, we will now learn how to install Node.js using fnm. 🎉
Managing Node.js versions with fnm
To download and install specific versions
of Node.js, use the following syntax:
fnm install <version>
For example, this command installs 14.15.0 on the dev machine:
fnm install 14.15.0
Alternatively, if you want to use the latest version, simply use the --latest flag, like so:
fnm install --latest
Otherwise, to install the LTS version, just pass the --lts argument:
Listing all Node.js versions
This bash command tells fnm to list all Node versions that are available to download:
fnm ls-remote
If you want to see what versions are installed on the system, just write:
fnm list
As you can see, in my case, two Node.js versions (18 and 19) were installed on the local machine. 📦✨
Using a particular version of Node.js
To use a specific version of Node, we have to run the use command. It follows this syntax:
fnm use <version>
For example, if you want your computer to switch to Node 19.3.0:
fnm use 19.3.0
We can verify that we’ve changed our version with the current command:
fnm current
This indicates that our machine is now running Node version 19.3.0. 🎯🚀
Uninstalling Node.js versions
To purge certain Node installations, use the uninstall keyword like so:
fnm uninstall <version>
For example, this removes Node 19.3.0 :
fnm uninstall 19.3.0 #uninstall the latest version of node
Setting Node.js version aliases
Aliases allow developers to “name” certain Node versions semantically. This is a great feature because it means that programmers don’t need to remember multiple Node versions if they’re working on many projects.
To set an alias, use this syntax:
fnm alias <version> <name>
For example,
fnm alias 18.12.1 my-project
The above command assigns the my-project alias to Node version 18.12.1.
To verify whether our alias was successfully configured, we can re-run fnm list:
Uninstalling fnm
In some cases, developers might encounter bugs, such as command issues during development. As a result, you may have to reinstall the fnm tool to fix this. In this section, you will learn how to delete fnm from your machine.
To purge fnm, we have to first find its installation directory:
fnm env #get all environment variables
Find the fnm installation directory:
Here, the FNM_DIR variable indicates the location of fnm. As the next step, go to the path and simply remove the fnm folder like so:
#in this case, fnm was in the 'share' folder
cd $HOME/.local/share
rm -rf fnm #removing this folder will uninstall this software
And we’re done! 👋✨
Alternatives to fnm
NVM
NVM (Node version manager) is an alternative to fnm that allows developers to install and manage their Node installs. Some sample commands include:
nvm use 18.15.0 #use a certain Node version
nvm install --lts #install Node to local machine
When compared to fnm, you might notice that it is far slower. Furthermore, this application doesn’t support Windows operating systems. As a workaround, The nvm team recommends nvm-windows, but it is not officially supported. ⚙️🐌
Volta
Similar to nvm, Volta is also a Node version management tool. Just like fnm, it was also built with Rust, thus bringing stability and speed to the table. Moreover, it lets creators “pin” certain Node engines. This means that if there’s a project that relies on a certain Node install, Volta will automatically switch to that Node version to prevent instability
issues in the stack.
volta install node # install latest Node LTS
volta pin node@14 # tell Volta that our project will use this node version
Conclusion
Since its launch, Fast Node Manager has become the default way to install Node on my computer. Although other alternatives like nvm and Volta exist, fnm has always been my tool of choice because of its speed and simplicity.
Thank you so much for reading! Happy coding! 🚀🎉