Skip to content

Instantly share code, notes, and snippets.

@bitdivine
Last active August 29, 2015 14:01
Show Gist options
  • Save bitdivine/309a1594e891dec70461 to your computer and use it in GitHub Desktop.
Save bitdivine/309a1594e891dec70461 to your computer and use it in GitHub Desktop.
Install the latest stable nodejs
#!/bin/sh
set -eux
INSTALL_DIR=/opt/nodejs
CURRENT=$(node -v || true)
VERSION=$(curl -L -s http://nodejs.org/dist/latest/ \
| egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \
| tail -n1)
PLATFORM="$(uname | tr 'A-Z' 'a-z')"
ARCH="$(uname -m | sed 's/x86_64/x64/g')"
PREFIX="$INSTALL_DIR/node-v$VERSION-$PLATFORM-$ARCH"
if test "v$VERSION" != "$CURRENT"; then
echo "Installing node v$VERSION ..."
mkdir -p "$PREFIX" && \
curl -# -L http://nodejs.org/dist/v$VERSION/node-v$VERSION-$PLATFORM-$ARCH.tar.gz \
| tar xzvf - --strip-components=1 -C "$PREFIX"
rm -f /usr/local/bin/node /usr/local/bin/npm
ln -s /opt/nodejs/node-v$VERSION-$PLATFORM-$ARCH/bin/node /usr/local/bin/node
ln -s /opt/nodejs/node-v$VERSION-$PLATFORM-$ARCH/bin/npm /usr/local/bin/npm
else
echo "Latest stable version of node already installed."
fi

This is a portable nodejs installer with no dependencies other than shell. It is based on an original by fhemberger but changed so that it works on:

  • Ubuntu 13, 14
  • Debian 5, 6, 7
  • OS-X v 10.9

Usage:

$ git clone https://gist.github.com/309a1594e891dec70461.git
$ cd 309a1594e891dec70461/
$ sudo sh node-installer.sh

or as a curl one-liner:

 # curl "https://gist.githubusercontent.com/bitdivine/309a1594e891dec70461/raw/4a96a04dfa179eee531647347c485a8750b9ea66/install-nodejs.sh" | tee node-installer.sh | sh

Original notes:

Starting with node v0.8.6, we're gonna be releasing official binary tarballs of the releases for the most common platform+architecture combos.

Here's a simple script that will install the latest stable node using a simple curl | tar piping. By default the files will get installed into your HOME directory. Change the PREFIX variable to /usr/local if you're feeling ambitious (note: you may need to run this as root depending on the PREFIX).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment