Skip to content

Instantly share code, notes, and snippets.

@chorrell
Created April 12, 2012 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chorrell/2369564 to your computer and use it in GitHub Desktop.
Save chorrell/2369564 to your computer and use it in GitHub Desktop.
add new version of nodejs to a SmartMachine
#!/usr/bin/env bash
#
# Add new version of nodejs to a SmartMachine
#
# Check to see if script is being run as the root user
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Aborting..." 1>&2
exit 1
fi
VERSION=$1
if [ -z "$VERSION" ]; then
echo "Usage: $0 <version> (e.g. 0.6.0)"
exit 127
fi
# Is the gcc compiler installed? If not, install
pkgin list | grep -q gcc-compiler
if [ $? -eq 1 ]; then
pkgin -f update # make sure the local repo is up to date
pkgin -y install gcc-compiler
fi
cd /var/tmp/
# Check if the version of node is installed, if so exit
if [ -e /opt/nodejs/v${VERSION}/ ]; then
echo "/opt/nodejs/v${VERSION}/ exists. ${VERSION} Already installed?"
exit 1
fi
# Download, make and compile node
curl -O http://nodejs.org/dist/v${VERSION}/node-v${VERSION}.tar.gz
gtar -xpf node-v${VERSION}.tar.gz
cd node-v${VERSION}/
./configure --with-dtrace --prefix=/opt/nodejs/v${VERSION}/
gmake install
# Clean up
cd /var/tmp/
rm -rf /var/tmp/node-v${VERSION}*
# Setup the symlink
if [ -e /opt/local/bin/node ]; then
if [ -L /opt/local/bin/node ]; then
rm /opt/local/bin/node
fi
fi
ln -s /opt/nodejs/v${VERSION}/bin/node /opt/local/bin/node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment