Installing NVM for Node and NPM.
Or: Using the Node Version Manager to... Manage Node Versions?
This post provides a step-by-step guide on how to install NVM (Node Version Manager) for managing Node and NPM versions. It covers everything from the prerequisites and installation of CURL to installing and activating NVM. It then details how to use NVM to install Node LTS and NPM, setting Node LTS as the default NVM version, and confirming the installations. It also includes instructions on how to test the installation by creating and running a simple Node.js project.
The purpose of this post is to use NVM to install the latest Node LTS and NPM.
The Big Picture.
NVM (Node Version Manager) is capable of much more than is described in this post. For instance, I can have multiple versions on Node installed on my system(s) and, thanks to NVM, I can easily switch between any of them.
- A Debian-based Linux distro (I use Ubuntu).
- I update my system:
sudo apt clean && sudo apt update && sudo apt dist-upgrade -y && sudo apt --fix-broken install && sudo apt autoremove -y
- I install CURL:
sudo apt install -y curl
Installing the NVM.
- I install the NVM (Node Version Manager):
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
NOTE: The version numbers are listed on the GitHub page.
- I activate the NVM:
Using NVM to Install Node LTS and NPM.
- I use NVM to install the LTS version of Node:
nvm install --lts
NOTE: The Node and NPM versions are listed on the screen.
Making Node LTS the Default NVM Version.
- I make Node LTS the default NVM version, as listed in the previous section:
nvm alias default 20.11.0
Confirming the Installations.
- I confirm the Node installation:
- I confirm the NPM installation:
Testing the Installation.
- I make, and change into, a new directory:
mkdir ./test-node-project && cd ./test-node-project
- I initialize a new Node project:
npm init -y
NOTE: This command will create a
- I use the Nano text editor to create a file called
sudo nano app.js
- I add the following, save (CTRL + S) the changes, and close (CTRL + X) the Nano text editor:
console.log("Hello, Node.js from Ubuntu!");
- I run the following command:
NOTE: A successful test result has the "Hello, Node.js from Ubuntu!" message printed to the terminal.
Installing NVM on a Debian-based Linux system like Ubuntu allows for easy management of Node.js and NPM versions. This guide walked through the necessary steps, from installing CURL and NVM, to installing and setting the default Node LTS and NPM versions. The successful execution of a simple Node.js project confirmed the installation processes. With NVM, I can now effortlessly switch between different Node versions as needed, enhancing my development workflow.
I've struggled with managing different versions of Node.js and NPM on my system, but here's the solution: Node Version Manager (NVM). NVM lets me install, manage, and switch between different versions of Node.js and NPM with ease.
I've crafted a step-by-step guide on how I install and use NVM on a Debian-based Linux system (like Ubuntu). From installing the prerequisites like CURL, to setting up NVM, and finally running a simple Node.js project to test the installation, this guide has me covered.
Key takeaway? NVM let's me effectively control my Node.js environment, there by enhancing my development workflow. Node.js version management is now easier and more efficient.
Have you tried NVM? How was your experience? Share your thoughts in the comments!
Until next time: Be safe, be kind, be awesome.