Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Download appropriate Node.js binaries
#!/bin/sh
set -e
error() { echo "error: $@"; exit 1; }
swhich() { which "$1" 2>&1 > /dev/null; }
[ -z "$DESTINATION" ] && DESTINATION=instanode
[ -z "$NODE_VERSION" ] && NODE_VERSION=v5.0.0
if [ -n "$HTTP_CMD" ]; then
true
elif swhich curl; then
HTTP_CMD='curl -s -O'
elif swhich wget; then
HTTP_CMD='wget -q'
else
error 'curl or wget required'
fi
[ -z "$ARCH" ] && ARCH=`uname -m`
[ -z "$SYSTEM" ] && SYSTEM=`uname -s`
case "$ARCH" in
x86_64) NODE_ARCH=x64;;
i686) NODE_ARCH=x86;;
arm7l) NODE_ARCH=armv7l;;
*) error "unrecognized arch $ARCH";;
esac
case "$SYSTEM" in
Linux) NODE_SYSTEM=linux;;
Darwin) NODE_SYSTEM=darwin;;
*) error "unrecognized system $SYSTEM";;
esac
NODE_DIR="node-$NODE_VERSION-$NODE_SYSTEM-$NODE_ARCH"
NODE_TAR="$NODE_DIR.tar.gz"
NODE_URL="https://nodejs.org/dist/$NODE_VERSION/$NODE_TAR"
mkdir -p "$DESTINATION"
cd "$DESTINATION"
$HTTP_CMD "$NODE_URL"
tar xf "$NODE_TAR"
mv "$NODE_DIR"/* .
rmdir "$NODE_DIR"
rm "$NODE_TAR"
./bin/node -e 'console.log(process.versions)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.