Skip to content

Instantly share code, notes, and snippets.

@mdesantis
Last active December 2, 2023 15:58
Show Gist options
  • Save mdesantis/ecc71e7e9bbf011ceb9711feea2e5b88 to your computer and use it in GitHub Desktop.
Save mdesantis/ecc71e7e9bbf011ceb9711feea2e5b88 to your computer and use it in GitHub Desktop.

Revisions

  1. mdesantis revised this gist Dec 2, 2023. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions nodejs-latest-lts-version.sh
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ set -o nounset
    # - cut
    # - tr

    nodejs_lts_latest_version_major=$(
    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
    @@ -21,9 +21,9 @@ nodejs_lts_latest_version_major=$(
    tr -d 'v'
    )

    echo "$nodejs_lts_latest_version_major" # Prints 20 (as at the time of writing the latest Node.js LTS is 20.x)
    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_lts_latest_version_major.x" | sudo -E bash -
    # curl -fsSL "https://deb.nodesource.com/setup_$nodejs_latest_lts_major.x" | sudo -E bash -
    # sudo apt-get install -y nodejs

  2. mdesantis revised this gist Dec 2, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nodejs-latest-lts-version.sh
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ set -o nounset
    nodejs_lts_latest_version_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
    # 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 | \
  3. mdesantis revised this gist Dec 2, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nodejs-latest-lts-version.sh
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ nodejs_lts_latest_version_major=$(

    echo "$nodejs_lts_latest_version_major" # Prints 20 (as at the time of writing the latest Node.js LTS is 20.x)

    # The version may be used to install the latest LTS version, e.g.:
    # The value may be used to install the latest LTS version, e.g.:
    # curl -fsSL "https://deb.nodesource.com/setup_$nodejs_lts_latest_version_major.x" | sudo -E bash -
    # sudo apt-get install -y nodejs

  4. mdesantis created this gist Dec 2, 2023.
    29 changes: 29 additions & 0 deletions nodejs-latest-lts-version.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/usr/bin/env bash

    set -o errexit
    set -o pipefail
    set -o nounset

    # Requirememnts:
    # - curl
    # - jq
    # - cut
    # - tr

    nodejs_lts_latest_version_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
    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_lts_latest_version_major" # Prints 20 (as at the time of writing the latest Node.js LTS is 20.x)

    # The version may be used to install the latest LTS version, e.g.:
    # curl -fsSL "https://deb.nodesource.com/setup_$nodejs_lts_latest_version_major.x" | sudo -E bash -
    # sudo apt-get install -y nodejs