Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NodeJS installer
#!/bin/bash -e
NODE_ARCHIVE_REPOSITORY=http://nodejs.org/dist/latest/
# Move to a temp directory
BUILD_DIR=$(mktemp -t -d "nodejs-installer.XXXXX")
cd $BUILD_DIR
archive=$(curl "${NODE_ARCHIVE_REPOSITORY}SHASUMS.txt" 2>/dev/null | egrep "node-v[0-9.]*.tar.gz" | cut -f3 -d" ")
download_archive="$NODE_ARCHIVE_REPOSITORY$archive"
directory=${archive%.tar.gz}
version=${directory#node-}
installed_version=$(node --version)
if [ $installed_version = $version ]; then
echo "${version} already installed, aborting..."
exit 1
else
echo "Installed: ${installed_version}"
echo "Lastest: ${version}"
echo ""
echo "About to installing new version..."
fi
# Require root privilegies right now to have it at install (final step)
sudo ls > /dev/null
echo "Downloading"
wget "$download_archive"
tar -zxf $archive
echo "Start building node $version"
cd $directory
./configure
make
sudo make install
echo "$directory successfully installed"
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.