Last active
February 13, 2019 15:30
-
-
Save elmarx/99210ca8445c22a97fce to your computer and use it in GitHub Desktop.
Automated (binary) install of the most recent NodeJS version to ~/.local/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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