CodeDigit
Back to Home

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

Admin User

Admin User

May 31, 2025 05:38 PM · 5 min read

Developer
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.


Tags

Node.js

Comments (0)

Leave a comment

Related Posts