Install

VERSION="$(curl -Ls https://api.github.com/repos/creationix/nvm/releases/latest | jq -r '.tag_name')"
curl -Lo- "https://raw.githubusercontent.com/creationix/nvm/${VERSION}/install.sh" | bash

Install NodeJS

VERSION="$(nvm ls-remote --lts | grep 'Latest LTS:' | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -k 1.2nr | head -n 1)"
nvm install "${VERSION}"
nvm alias default "${VERSION}"
nvm use default

Note

You may have to restart your shell or otherwise fix your environment...

Remove old NodeJS Versions

nvm ls --no-colors | grep -Ev '^->' | grep '^ ' | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+' | while read VERSION; do nvm uninstall "${VERSION}"; done