How to Install Node.js using NVM in Linux
NVM (Node Version Manager) is a tool that allows you to install and manage multiple versions of Node.js on your system.
Why Use NVM?
- Multiple versions: Switch between different Node.js versions easily
- Project-specific versions: Use different Node.js versions for different projects
- Easy updates: Update Node.js versions without system conflicts
- No sudo required: Install Node.js without administrator privileges
Step 1: Install NVM
First, download and install NVM using curl:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
Step 2: Reload Your Shell
After installation, reload your shell configuration:
source ~/.bashrc
Step 4: Install Node.js
Install the latest LTS version:
nvm install --lts
Step 5: Use Node.js Version
Switch to a specific version:
nvm use 18.17.0
Useful NVM Commands
nvm list
- List installed versionsnvm list-remote
- List available versionsnvm current
- Show current versionnvm uninstall <version>
- Remove a version
Conclusion
NVM makes it easy to manage Node.js versions on Linux. It’s especially useful for developers working on multiple projects that require different Node.js versions.