Skip to content

Instantly share code, notes, and snippets.

@chorrell chorrell/
Created May 29, 2012

What would you like to do?
Add new version of nodejs to a nodejs or SmartMachine
#!/usr/bin/env bash
# Add new version of nodejs to a nodejs or 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
if [ -z "$VERSION" ]; then
echo "Usage: $0 <version> (e.g. 0.6.0)"
exit 127
# 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
# Don't create the src dir if it already exists
if [ ! -e ~/src/ ]; then
mkdir ~/src
cd ~/src
# 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
# Download, make and compile node
curl -O${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 but leave the ~/src directory
cd ~/
rm -rf ~/src/node-v${VERSION}*
# Update the symlink so the local version of node is in sync
rm /home/node/local/nodejs
ln -s /opt/nodejs/v${VERSION} /home/node/local/nodejs
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.