nvm install one-liner without hardcoded version number
if you want to install NVM to then install one or multiple versions of node.js you can find simple installation instructions right on their github page. those instructions include a curl
one-liner that will run the install script. the only problem is, that the version number of the latest release is “hardcoded”, i.e. they update the installation docs on every new release. Now if you want to automate the installation for example in a Dockerfile and you want to make sure you always get the latest version, you can use the github api to first find the version number of the latest release and then replace that version number in the download link with it.
here is how you get the version number of the latest nvm release from the API:
curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep "tag_name" | cut -d : -f 2,3 | tr -d ' ",'
note: you could also use jq to parse the json received from the github api, however, i felt that using grep
cut
and tr
instead i could get away without introducing a possibly unmet dependency.
and here is the one-liner to download the install.sh
file from the latest release:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/$(curl -s https://api.github.com/repos/nvm-sh/nvm/releases/latest | grep "tag_name" | cut -d : -f 2,3 | tr -d ' ",')/install.sh | bash