Setting Up Your Environment with NVM
Master NVM to manage Node.js versions like a pro. Learn to install, switch, and verify your Node.js environment for consistent, error-free backend development.
Previously in this course, we explored Understanding the Node.js Architecture to see how the engine processes code. Now that you understand the "why" behind the runtime, it's time to set up the "how."
If you install Node.js directly from the official website, you’ll likely end up with one global version. This is a common trap: different projects often require different versions of Node.js. If you upgrade to test a new feature, you might accidentally break an older project relying on an outdated API.
The industry-standard solution to this problem is NVM (Node Version Manager). It allows you to install multiple versions of Node.js side-by-side and switch between them with a single command.
What is NVM and Why Use It?
NVM is a CLI tool that manages your Node.js installation directory. Instead of the system-wide installation, NVM keeps versions isolated in your user folder.
| Feature | Global Node.js Installation | NVM Managed |
|---|---|---|
| Version Control | Single version only | Multiple versions |
| Permissions | Often requires sudo | No sudo required |
| Flexibility | Difficult to downgrade | Instant switching |
| Safety | Risk of breaking system tools | Isolated environment |
Installing NVM
To install NVM, you need to run the installation script from their official repository. Open your terminal and use curl or wget.
For macOS and Linux
Run the following command in your terminal:
Bashcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
After the script completes, close your terminal and reopen it, or run source ~/.bashrc (or source ~/.zshrc if you use Zsh). Verify the installation by typing:
Bashnvm --version
If you see a version number, you're ready to go.
For Windows
The official NVM script is for Unix-based systems. For Windows, download the nvm-windows installer. It provides a similar CLI experience but handles Windows-specific paths.
Managing Node.js Versions
Once NVM is installed, you don't need to download Node.js from the website anymore. You manage everything through the nvm command.
Installing a Version
To install the latest Long Term Support (LTS) version of Node.js:
Bashnvm install --lts
If you need a specific version (e.g., v18.16.0):
Bashnvm install 18.16.0
Switching Versions
You can switch between installed versions instantly. To use a specific version in your current terminal session:
Bashnvm use 18.16.0
Verifying Installation
Always verify your current version after switching to ensure your terminal is pointing to the right environment:
Bashnode -v
If you see the expected version number, your environment is correctly configured.
Hands-on Exercise
- Use
nvm install 16.0.0to install an older version. - Use
nvm install --ltsto install the newest stable version. - List your installed versions using
nvm ls. - Switch between them using
nvm useand verify the version withnode -veach time.
Common Pitfalls
- "Command not found": This usually happens if you haven't sourced your shell profile after installation. Ensure your
.bashrcor.zshrccontains the NVM export lines. - Forgetting to use
nvm use: NVM does not automatically switch versions when you enter a directory unless you use an.nvmrcfile (which we will cover later). Always check yournode -vif things act strangely. - Mixing Global and NVM: If you previously installed Node via a package manager like
breworapt, uninstall those global versions to avoid conflicts with NVM.
FAQ
Do I need to reinstall my global packages every time I switch versions?
Yes. Global packages (like nodemon or typescript) are installed specifically for the active Node version. Use nvm install --lts --reinstall-packages-from=current to migrate them.
Is NVM the only way to manage versions?
No, tools like fnm (Fast Node Manager) or volta are popular alternatives, but NVM remains the most widely used and documented tool in the ecosystem.
Recap
You’ve now installed NVM, learned how to manage multiple Node.js versions, and verified your setup. This isolation is critical for building a stable REST API, as it ensures your project works exactly the same way on your machine as it will on your production server.
Up next: We will dive into the REPL and learn how to run your first JavaScript files.
Work with me

WooCommerce Store Setup & Customization
A WooCommerce store that's set up right, customized to your brand, and ready to sell — by a developer who builds WooCommerce products, not just stores.

VPS Server Setup, Deployment & Hardening
Get your app live on a fast, secure server — properly configured, hardened, and deployment-ready. No more wrestling with the command line.


