#!/usr/bin/env bash set -o errexit set -o pipefail set -o nounset # Requirememnts: # - curl # - jq # - cut # - tr nodejs_latest_lts_major=$( # Fetch Node.js versions metadata curl -fsSL https://nodejs.org/dist/index.json | \ # Reject items with falsey "lts" value | sort by "lts" | get the latest item's "version" value jq --raw-output 'map(select(.lts)) | sort_by(.lts) | .[-1].version' | \ # v20.10.0 => v20 cut -d '.' -f 1 | \ # v20 => 20 tr -d 'v' ) echo "$nodejs_latest_lts_major" # Prints 20 (as at the time of writing the latest Node.js LTS is 20.x) # The value may be used to install the latest LTS version, e.g.: # curl -fsSL "https://deb.nodesource.com/setup_$nodejs_latest_lts_major.x" | sudo -E bash - # sudo apt-get install -y nodejs