NVM (Node Version Manager) lets you install multiple Node.js versions and switch between them with a single command. This is essential for developers working on multiple projects with different Node.js requirements on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server or desktop
- A user account (NVM is installed per-user, not system-wide)
Step 1 – Install NVM
Download and run the NVM install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
Step 2 – Activate NVM
Load NVM into the current session:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
Or simply open a new terminal — NVM adds itself to ~/.bashrc automatically.
Step 3 – Verify NVM
Confirm NVM is installed:
nvm --version
Step 4 – Install Node.js Versions
Install Node.js 20 LTS and the latest version:
nvm install 20
nvm install node # latest
List installed versions:
nvm ls
Step 5 – Switch Between Versions
Use a specific version:
nvm use 20
Set a default version for new shells:
nvm alias default 20
Step 6 – Use a .nvmrc File
Pin a project to a specific Node version:
echo '20' > /path/to/project/.nvmrc
cd /path/to/project && nvm use
Step 7 – Uninstall a Version
Remove a specific Node.js version:
nvm uninstall 18
Conclusion
NVM is now set up on Ubuntu 24.04 LTS. It provides fine-grained control over Node.js versions per project without requiring root access or affecting global system packages.