Skip to content

Instantly share code, notes, and snippets.

@alexolinux
Last active July 4, 2025 22:19
Show Gist options
  • Save alexolinux/117211194783a1a11a38e6aee2d4bafb to your computer and use it in GitHub Desktop.
Save alexolinux/117211194783a1a11a38e6aee2d4bafb to your computer and use it in GitHub Desktop.
Script to install Node Version Manager (NVM).
#!/bin/bash
#https://github.com/nvm-sh/nvm/releases
NVM_VER="v0.40.3"
# Check if NVM is already installed
if [ -z "$(command -v nvm)" ] && [ -z "$NVM_DIR" ]; then
echo "---- NVM Installation ----"
# Check if curl is installed
if [ ! -z "$(command -v curl)" ]; then
echo "Downloading nvm..."
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VER}/install.sh" | bash
# Check if download and installation succeeded
if [ "$?" -eq 0 ]; then
echo "NVM installed successfully!"
echo "Restart your SHELL Session."
else
echo "Error installing NVM."
exit 1
fi
else
echo "CURL Command not found. Install curl before proceeding with this script."
exit 1
fi
else
echo "NVM is already installed. Sourcing NVM initialization script..."
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm --version
fi
@alexolinux
Copy link
Author

alexolinux commented Apr 20, 2024

NVM Useful commands


  1. List available Node Versions
nvm ls-remote
  1. Install the Latest Version
nvm install --lts
  1. Install specific NodeJS version
nvm install x.x.x
nvm install v18.20.5
  1. Uninstall specific NodeJS version
nvm uninstall v18.20.5
  1. List Installed Node versions
nvm ls
  1. Set the default version
nvm alias default v20.12.2
  1. Use specific version
nvm use v20.12.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment