Created
July 11, 2016 19:21
-
-
Save djbobbydrake/d1d401aecc6b724eee6cb2a886c90425 to your computer and use it in GitHub Desktop.
Install node
This file contains 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
#!/bin/bash | |
# Predefined links and files. Note: LTS may not be latest LTS | |
export NODE_STABLE=http://nodejs.org/dist/node-latest.tar.gz | |
export NODE_LTS=https://nodejs.org/dist/latest-v4.x/node-v4.2.2.tar.gz | |
export RC_BASH=~/.bashrc | |
export RC_PROFILE=~/.profile | |
# Settings | |
export NODE_VER=$NODE_LTS | |
export RC_FILE=$RC_BASH | |
export UNSET_MANPATH=true # false if MANPATH already modifed elsewhere | |
export USE_GROUP=false # change group ownership | |
export GROUP_NAME=node # sudo groupadd $GROUP_NAME beforehand | |
# Download Node into current directory and extract | |
mkdir node-install | |
cd node-install | |
curl $NODE_VER | tar xz --strip-components=1 | |
# Export env variables and add to PATH | |
echo 'export NODE_DIR=/usr/local/node' >> $RC_FILE | |
echo 'export NPM_PACKAGES="$NODE_DIR/npm-packages"' >> $RC_FILE | |
echo 'export NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"' >> $RC_FILE | |
echo 'export PATH="$PATH:$NPM_PACKAGES/bin:$NODE_DIR/bin"' >> $RC_FILE | |
# MANPATH | |
if [ "$UNSET_MANPATH" == "true" ]; then | |
echo 'unset MANPATH' >> $RC_FILE | |
fi | |
echo 'export MANPATH="$NPM_PACKAGES/share/man:$MANPATH"' >> $RC_FILE | |
# Source | |
source $RC_FILE | |
# Make directories for Node and npm global packages | |
sudo mkdir $NODE_DIR | |
sudo mkdir $NPM_PACKAGES | |
# Take ownership | |
if [ "$USE_GROUP" == "false" ]; then | |
sudo chown `whoami` $NODE_DIR | |
else | |
sudo chgrp $GROUP_NAME $NODE_DIR | |
fi | |
# Configure and install | |
./configure --prefix=$NODE_DIR | |
# This will take a while, 20-30 mins or so. Building V8! | |
make install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment