Install NVM (Node Version Manager) on Ubuntu
Summary
NVM (Node Version Manager) is a tool that allows you to install and manage multiple versions of Node.js on your system. This tutorial will guide you through installing NVM and using it to manage Node.js versions.
Key Vocabulary
Prerequisites
- Ubuntu 18.04 or later
- Internet connection
- Basic command line knowledge
Step-by-Step Instructions
Update Package List
Update your system's package list.
sudo apt update
Install curl
Install curl if it's not already available on your system.
sudo apt install curl
Download and Install NVM
Download and run the NVM installation script.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Load NVM in Current Session
Load NVM into your current shell session.
source ~/.profile
Verify NVM Installation
Check that NVM is properly installed.
nvm --version
Install Latest LTS Node.js
Install the latest Long Term Support version of Node.js.
nvm install --lts
Install Specific Node.js Version
Install a specific version of Node.js (version 20 in this example).
nvm install 20
List Installed Node.js Versions
View all Node.js versions installed on your system.
nvm ls
Switch to LTS Version
Switch to using the LTS version of Node.js.
nvm use --lts
Common Issues & Solutions
Solution: Run 'source ~/.profile' or restart your terminal. NVM needs to be loaded into your shell session.
Solution: The installation script should be run as your regular user, not with sudo. NVM installs to your home directory.
Solution: Install curl first with 'sudo apt install curl' before running the NVM installation.
Solution: Check your internet connection and try again. The script downloads from GitHub.
Conclusion
Congratulations! You have successfully installed NVM and learned how to manage Node.js versions. NVM makes it easy to switch between different Node.js versions for different projects.
Next steps:
- Install your preferred Node.js version with 'nvm install [version]'
- Switch between versions with 'nvm use [version]'
- Set a default version with 'nvm alias default [version]'
- Check available versions with 'nvm ls-remote'
NVM will automatically load when you open a new terminal session, so you can start using it immediately!