Skip to content

Instantly share code, notes, and snippets.

@elmarx
Last active February 13, 2019 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmarx/99210ca8445c22a97fce to your computer and use it in GitHub Desktop.
Save elmarx/99210ca8445c22a97fce to your computer and use it in GitHub Desktop.
Automated (binary) install of the most recent NodeJS version to ~/.local/
#!/bin/sh -
set -o errexit
set -o nounset
PREFIX=$HOME/.local/node
if ! command -v curl > /dev/null || ! command -v jq > /dev/null; then
echo "this script requires curl and jq"
exit 1
fi
VERSION=$(curl -s https://nodejs.org/dist/index.json | jq -r 'sort_by(.version)|reverse|.[0].version')
if command -v node && [ "$(node --version)" = "${VERSION}" ]; then
echo "Nothing to do, node ${VERSION} already installed"
exit
fi
echo "Installing version ${VERSION}"
# remove the present node installation
if [ -d $PREFIX ]; then
rm -rf $PREFIX
fi
mkdir -p $PREFIX
# download and extract nodejs
curl -s https://nodejs.org/dist/${VERSION}/node-${VERSION}-linux-x64.tar.xz | tar xJf - -C ${PREFIX} --strip 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment