Skip to content

Instantly share code, notes, and snippets.

@rogerbush8
Last active August 29, 2015 14:16
Show Gist options
  • Save rogerbush8/6a02512e7f275c757e0c to your computer and use it in GitHub Desktop.
Save rogerbush8/6a02512e7f275c757e0c to your computer and use it in GitHub Desktop.
install-and-build-nodejs-from-source
#### Pulls Nodejs Source, Builds and Installs
#
# I've run this successfully on an AWS EC2 instance running a RHEL AMI. It
# should work fine for installs on recent RHEL descended distros.
#
# Installation is done by pulling this script from curl, and piping it
# through bash, with appropriate parameters. This must be run as root,
# and local files (e.g. temp files) will be created relative to the
# current working directory.
#
# To invoke, see "Script Parameters" below, and note name on right-hand-side
# of each. Below is an example of how to invoke the script:
#
# $ screen # In case you are ssh'd, so disconnect won't cause issues
# $ sudo su - # Must be run as root
# $ cd <somewhere> # Tar files will be relative to current working dir
#
# # The following line is an example that does the heavy lifting of the install.
# # (make sure to get the URL from [RAW])
#
# $ curl https://gist.github.com/.../raw/...<this> | $VERSION=11.0 $VAR2 bash -s
#
#### Script Parameters (pass in name on right-hand-side of expression)
NODE_VERSION=${VERSION:-12.0} # Default 12.0. Check version you specify exists.
#### Step 1: Test for yum and root
if [ -z `which yum` ] ; then
echo "yum not found. Install script assumes RHEL-related distro with yum enabled. Aborting..." >&2
exit 1
fi
if [ `whoami` != "root" ] ; then
echo "user not root. Install script assumes run as root (try: 'sudo su -' first). Aborting..." >&2
exit 2
fi
#### Step 1: Update and install developer tools to compile nodejs
yum -y update
yum -y group install "Development Tools"
#### Step 2: Get node source and unpack into directory
DIRNAME="node.${NODE_VERSION}"
mkdir $DIRNAME
cd $DIRNAME
FILENAME="node-v0.${NODE_VERSION}"
wget http://nodejs.org/dist/v0.${NODE_VERSION}/${FILENAME}.tar.gz
gunzip ${FILENAME}.tar.gz
tar -xvf ${FILENAME}.tar
# untarring creates a top-level dir named $FILENAME. Descend into it
cd $FILENAME
#### Build from src
./configure
make
make install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment