Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Keep up to date with the latest version of node.js
#!/bin/bash
sudo apt-get -qq install build-essential g++ apache2-utils libssl-dev curl
latest_dir="http://nodejs.org/dist/latest/";
latest_version=$(curl -s "$latest_dir" | grep "tar\.gz" | sed -re 's/.*?href="node-(v[0-9\.]+)\.tar\.gz".*/\1/');
cleanup() {
rm -rf "$temp";
}
earlydeath() {
cleanup;
exit 1;
}
error() {
echo >&2 "ERROR: There was a problem $1.";
earlydeath;
}
local_version() {
echo $(node --version);
}
if [ ! -z "`which node`" ]; then
version=$(local_version);
newest=$(echo -e "$latest_version\n$version" | sort -V | tail -1);
if [ "$version" == "$newest" ]; then
echo "Already up to date.";
exit 0;
fi
fi
trapped() {
echo >&2 "Caught signal, cleaning up...";
earlydeath;
}
trap trapped INT TRAP HUP;
temp=$(mktemp -d '/tmp/nodejs-XXX');
curl -s "$latest_dir/node-$latest_version.tar.gz" | tar xz -C "$temp" || error "downloading or decompressing";
cd "$temp"/node-* || "with the decompressed file";
./configure --prefix=/usr || error "configuring";
JOBS=`grep processor /proc/cpuinfo | wc -l` make || error "compiling";
sudo make install || error "installing";
cleanup;
echo "node.js version now at `local_version`";
@danbeam

This comment has been minimized.

Copy link
Owner Author

@danbeam danbeam commented Nov 30, 2011

Run easily with something like this

raw="https://raw.github.com/gist/1410275/7b44c30cca9dcadab19806d43868496f4525e20a/update-nodejs.bash"
curl -s "$raw" | bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment