Created
July 17, 2014 02:34
-
-
Save wesleytodd/a74df4e6d42f54c3263a to your computer and use it in GitHub Desktop.
Ways to install node.js in bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Inspired by: | |
# https://github.com/visionmedia/n/blob/master/bin/n | |
# http://stackoverflow.com/a/8597411 | |
# | |
# Detect Platform | |
if [[ "$OSTYPE" == "linux-gnu" ]]; then | |
PLATFORM=linux | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
PLATFORM=darwin | |
elif [[ "$OSTYPE" == "win32" ]]; then | |
echo "Windows not supported" | |
exit 1 | |
else | |
echo "Unknown or unsupported platform, defaulting to linux" | |
PLATFORM=linux | |
fi | |
# Detect Architecture | |
if [[ "$(arch)" == "x86_64" ]]; then | |
ARCH=x64 | |
elif [[ "$(arch)" == "i386" ]]; then | |
ARCH=x86 | |
else | |
echo "Unknown Architecture, defaulting to x86" | |
ARCH=x86 | |
fi | |
# Get latest stable version | |
GET= | |
command -v wget > /dev/null && GET="wget --no-check-certificate -q -O-" | |
command -v curl > /dev/null && GET="curl -# -L" | |
test -z "$GET" && abort "curl or wget required" | |
if [[ -z "$GET" ]]; then | |
echo "Could not get version, defaulting to 0.10.29" | |
VERSION=0.10.29 | |
else | |
VERSION=`$GET 2> /dev/null http://nodejs.org/dist/ | egrep -o '[0-9]+\.[0-9]*[02468]\.[0-9]+' | sort -u -k 1,1n -k 2,2n -k 3,3n -t . | tail -n1` | |
fi | |
# Get latest stable version | |
GET= | |
command -v wget > /dev/null && GET="wget --no-check-certificate -q -O-" | |
command -v curl > /dev/null && GET="curl -# -L" | |
test -z "$GET" && abort "curl or wget required" | |
if [[ -z "$GET" ]]; then | |
echo "Could not get version, defaulting to 0.10.29" | |
VERSION=0.10.29 | |
else | |
VERSION=`$GET 2> /dev/null http://nodejs.org/dist/ | egrep -o '[0-9]+\.[0-9]*[02468]\.[0-9]+' | sort -u -k 1,1n -k 2,2n -k 3,3n -t . | tail -n1` | |
fi | |
# Install location | |
PREFIX=${N_PREFIX-/usr/local} | |
if [ "$(which node)" == "" ] || [ "$(node -v)" != "v$VERSION" ]; then | |
echo "===============================" | |
echo "Installing Node" | |
echo "===============================" | |
mkdir -p "$PREFIX" | |
curl http://nodejs.org/dist/v$VERSION/node-v$VERSION-$PLATFORM-$ARCH.tar.gz | tar xzvf - --strip-components=1 -C "$PREFIX" | |
rm $PREFIX/ChangeLog $PREFIX/LICENSE $PREFIX/README.md | |
node -e "console.log('Node v$VERSION successfully installed!')" | |
else | |
node -e "console.log('Node v$VERSION already installed!')" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
GET= | |
command -v wget > /dev/null && GET="wget -q" | |
test -z "$GET" && abort "wget required" | |
PREFIX=${N_PREFIX-/usr/local} | |
$GET https://raw.githubusercontent.com/visionmedia/n/master/bin/n -O $PREFIX/bin/n && chmod +x $PREFIX/bin/n | |
n stable 2> /dev/null | |
node -e "console.log('Node ' + process.version + ' successfully installed!')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment