Developer

Install Node.js and npm with NVM on Ubuntu (Beginner-Friendly Guide)

Learn how to install Node.js and npm using NVM on Ubuntu. This guide covers installing NVM, managing multiple Node.js versions, setting a default, and updating with ease.

By Admin User
21 views
Install Node.js and npm with NVM on Ubuntu (Beginner-Friendly Guide)

🚀 1. What Is NVM and Why Use It?

NVM (Node Version Manager) lets you install and manage multiple versions of Node.js on a single system. It's perfect for developers juggling projects with different Node requirements.


📦 2. Install NVM on Ubuntu

Step 1: Download and run the install script

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash 

Step 2: Load NVM into your terminal

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" 

Tip: To make NVM load automatically, add the above block to your ~/.bashrc, ~/.zshrc, or ~/.profile.

Step 3: Verify installation

nvm --version 

📥 3. Install Node.js Using NVM

List available Node.js versions:

nvm ls-remote 

Install the latest LTS version:

nvm install --lts 

Or install a specific version:

nvm install 18.19.0 

Verify installation:

node -v npm -v 

⚙️ 4. Set a Default Node.js Version

Set a default Node version globally:

nvm alias default 18.19.0 

From now on, every new terminal session will use this version unless overridden.


🔄 5. Switch Between Versions Easily

If you have multiple versions installed:

nvm use 16.20.0 

To list all installed versions:

nvm ls 

đź§ą 6. Uninstall a Node.js Version

To remove a version you no longer need:

nvm uninstall 16.20.0 

📎 7. Where Is npm Installed?

npm is automatically installed with Node.js via NVM. Check versions:

which node which npm 

They will typically point to paths like:

~/.nvm/versions/node/v18.19.0/bin/node 

âś… Conclusion

Using NVM on Ubuntu keeps your Node.js environment clean, flexible, and up to date. You can switch Node versions per project, test backward compatibility, or quickly adopt new releases—all without affecting your global system setup.

#Node.js

Share this article

Admin User

Admin User

Admin User

Related Posts

The Enduring Importance of Data Structures & Algorithms
Developer
5 min read

The Enduring Importance of Data Structures & Algorithms

In an age where AI seems to handle everything from chatbots to complex simulations, the fundamentals of Data Structures & Algorithms (DSA) remain the cornerstone of every efficient, scalable, and innovative software solution. Here’s why, even in 2025, DSA skills are non-negotiable for any developer aiming to thrive.

Guest User

Comments