Ever been stuck with a project that only works with Node.js v14 while your system has v22?
That’s where NVM (Node Version Manager) saves the day. If you're a JavaScript or Node.js developer, using NVM is almost essential. Let's break down why you should use NVM and how to set it up in less than 5 minutes.
🤔 Why Use NVM?
1. Switch Between Node.js Versions Effortlessly
Projects often require different Node.js versions. With NVM, you can switch between them with a single command:
nvm use 18
2. Isolate Project Dependencies
Avoid global conflicts. Each project can use its own Node.js version, so you're never stuck debugging weird issues due to mismatched versions.
3. Avoid Breaking Global Installs
Upgrading Node globally can break tools like npm
, yarn
, or next
. NVM keeps it safe by isolating installs.
4. Great for Open Source Contributions
Many open-source projects specify a Node.js version in .nvmrc
. With NVM, all you need is:
nvm use
…and you're good to go.
🛠️ How to Install NVM (Mac/Linux)
Step 1: Install via cURL or Wget
# using curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# or using wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Step 2: Add NVM to your shell profile
After installation, add this to your .bashrc
, .zshrc
, or .profile
:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Then restart your terminal or run:
source ~/.bashrc
# or
source ~/.zshrc
Step 3: Verify Installation
nvm --version
You should see something like 0.39.7
.
⚡ Using NVM
Install a Node version
nvm install 20
Use a specific version
nvm use 20
Set default version
nvm alias default 20
Check installed versions
nvm ls
📁 Bonus: Use .nvmrc
for Project-Level Versioning
Add a .nvmrc
file in your project root:
echo "18" > .nvmrc
Now, whenever you're in the project directory:
nvm use
📦 Windows? Try nvm-windows
If you're on Windows, use the nvm-windows fork:
- Download the installer from the release page
- Follow the setup instructions
- Done!
🚀 Final Thoughts
Whether you're working solo or contributing to multiple projects, NVM makes your Node.js workflow cleaner and safer. No more "version not supported" errors, no more global chaos.
Top comments (0)