# Set this environment variable pointing to ~/.nvm
export NVM_DIR="$HOME/.nvm"
# Get the source for the first time using Git
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" \
$(git rev-list --tags --max-count=1)`
# If you already have it, do this to update it
cd "$NVM_DIR"
git fetch --tags origin
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" \
$(git rev-list --tags --max-count=1)`
# Source it in to your current shell
. "$NVM_DIR/nvm.sh"
# Set it so this is done at login by updating ~/.profile
echo "export NVM_DIR=\"\$HOME/.nvm\"" >> ~/.profile
echo "[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\"" >> ~/.profile
echo "[ -s \"\$NVM_DIR/bash_completion\" ] &&" >> ~/.profile
echo " . \"\$NVM_DIR/bash_completion\"" >> ~/.profile
# Install Node.js, latest version
nvm install node
# List available versions
nvm ls-remote
# List installed versions
nvm ls
# Install Node.js, version 18.16.1
nvm install 18.16.1
# Install Node.js, version 16.20.1
nvm install 16.20.1
# Use a different version in the current shell
# (done automatically after installing)
nvm use 16.20.1
# Use Node.js version as the default in new shells
nvm alias default 16.20.1
# Display the path of the current version
nvm which current