Skip to content

Instantly share code, notes, and snippets.

@alexolinux
Last active July 27, 2025 11:28
Show Gist options
  • Select an option

  • Save alexolinux/117211194783a1a11a38e6aee2d4bafb to your computer and use it in GitHub Desktop.

Select an option

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 cheatsheet


  1. Version Management
  • List available versions
nvm ls-remote
  • List installed versions
nvm ls
  • Install a specific version
nvm install <version>
  • Install the latest version
nvm install node
  • Install the latest LTS version
nvm install --lts
  1. Using Node.js Versions
  • Use a specific version
nvm use <version>
  • Set default version
nvm alias default <version>
  • Unset default version
nvm unalias default
  1. Uninstalling Versions
nvm uninstall <version>
  1. Current Version Information
  • Show current version
nvm current
  • Check NVM version
nvm --version
  1. Cache Management
  • Clear NVM cache
nvm cache clear
  1. Alias
  • Create an alias for a version
nvm alias <alias-name> <version>
  • List all aliases
nvm alias
  1. Environment Variables
  • Set the NVM_DIR environment variable
export NVM_DIR="$HOME/.nvm"

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