Skip to content

Instantly share code, notes, and snippets.

@matths
Forked from shapeshifta78/install-nodejs.sh
Last active December 20, 2015 17:39
Show Gist options
  • Save matths/6170411 to your computer and use it in GitHub Desktop.
Save matths/6170411 to your computer and use it in GitHub Desktop.
#!/bin/sh
CURRENT=$(node -v)
#version details
VERSION=$(curl -L -s http://nodejs.org/dist/latest/ \
| egrep -o '[0-9]+\.[0-9]+\.[0-9]+' \
| tail -n1)
PLATFORM=linux
ARCH=x64
PREFIX="$HOME/node-v$VERSION-$PLATFORM-$ARCH"
if test "v$VERSION" != "$CURRENT"; then
echo "Installing node v$VERSION ..."
mkdir -p "$PREFIX"
#download binaries
curl http://nodejs.org/dist/v$VERSION/node-v$VERSION-$PLATFORM-$ARCH.tar.gz \
| tar xzvf - --strip-components=1 -C "$PREFIX"
#remove former version
sudo rm -fr $HOME/node-$CURRENT-$PLATFORM-$ARCH
#remove former symlinks
sudo rm -fr /usr/local/bin/node
sudo rm -fr /usr/local/bin/npm
#create symlinks
sudo ln -s $HOME/node-v$VERSION-$PLATFORM-$ARCH/bin/node /usr/local/bin/node
sudo ln -s $HOME/node-v$VERSION-$PLATFORM-$ARCH/bin/npm /usr/local/bin/npm
else
echo "Latest stable version of node already installed."
fi

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 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).

Adapted to latest node version and for 64Bit Linux.

Install using $ bash -c "$(curl -fsSL https://gist.github.com/matths/6170411/raw/install-nodejs.sh)"

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