Last active
April 2, 2024 16:51
-
-
Save rvagg/742f811be491a49ba0b9 to your computer and use it in GitHub Desktop.
install-node.sh - simple script to fetch and install Node.js releases and nightlies on Linux (x86, x64 & ARM) and OS X
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/bash | |
# Note your /usr/local will need to be writable by the user running it, | |
# alternatively run it with `sudo` | |
hasxz=$(which xzcat) | |
os=$(uname | tr '[A-Z]' '[a-z]') | |
arch=$(uname -m) | |
targetdir="/usr/local/" | |
domain=nodejs.org | |
tarargs=" --strip-components=1 --exclude ./CHANGELOG.md --exclude ./README.md --exclude ./LICENSE -C ${targetdir}" | |
[[ "$arch" == "x86_64" ]] && arch=x64 | |
[[ "$arch" == "x686" ]] && arch=x86 | |
[[ "$arch" == "x86" ]] && domain=unofficial-builds.nodejs.org | |
type=release | |
line="" | |
yorn="" | |
while [[ $# -gt 0 ]] | |
do | |
key="$1" | |
case $key in | |
-h|--help) | |
echo "Usage: install-node.sh [-h|--nightly] [-l|--line <release line>] [-y|--yes]" | |
echo " Where:" | |
echo " --nightly will fetch the latest nightly version instead of the latest release version" | |
echo " --line <release line> will let you select a major version, e.g. --line 10" | |
echo " (note --line will match as much of the version as you want, e.g. --line 10.12 or --line 10.12.0)" | |
echo " --yes will not promot you for confirmation before installing" | |
exit 1 | |
;; | |
-n|--nightly) | |
shift | |
;; | |
-y|--yes) | |
yorn="y" | |
shift | |
;; | |
-l|--line) | |
line="$2" | |
shift | |
shift | |
;; | |
*) | |
shift | |
;; | |
esac | |
done | |
latest=$(curl -sL https://${domain}/download/${type}/index.tab | grep "^v${line}" | awk '/^v[0-9]/{ print $1; exit }') | |
while true; do | |
if [ "X${yorn}" == "Xn" ]; then | |
break | |
fi | |
if [ "X${yorn}" == "Xy" ]; then | |
url="https://${domain}/download/${type}/$latest/node-${latest}-${os}-${arch}.tar" | |
if [ "X${hasxz}" == "X" ]; then | |
url="${url}.gz" | |
pipecmd="| tar -zx ${tarargs}" | |
else | |
url="${url}.xz" | |
pipecmd="| xzcat | tar -x ${tarargs}" | |
fi | |
echo "Downloading and unpacking ${url} to ${targetdir}..." | |
bash -c "curl -sL '${url}' ${pipecmd}" | |
break | |
fi | |
echo -n "Download and install Node.js ${latest} (${os}/${arch})? [y/n] " | |
yorn="" | |
read yorn | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rvagg Shouldn't
${os}-x64
be${os}-${arch}
?What's
'${auth}'
?