Skip to content

Instantly share code, notes, and snippets.

@nimasmi
Last active December 10, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nimasmi/5a0311023168481a4d22 to your computer and use it in GitHub Desktop.
Save nimasmi/5a0311023168481a4d22 to your computer and use it in GitHub Desktop.
Vagrant provision—Node installation snippet
#!/bin/bash
NODE_VERSION=v4.2.3 # amend this line only, to change Node version
# Node.js
if ! command -v npm; then
INSTALL_NODE=1
elif [ $NODE_VERSION != `node --version` ]; then
rm -rf /opt/node-`node --version`-linux-x64/
rm /usr/local/bin/node
rm /usr/local/bin/npm
INSTALL_NODE=1
else
INSTALL_NODE=0
fi
if [ $INSTALL_NODE = 1 ]; then
wget http://nodejs.org/dist/$NODE_VERSION/node-$NODE_VERSION-linux-x64.tar.gz
cd /opt && tar -xzf /home/vagrant/node-$NODE_VERSION-linux-x64.tar.gz
ln -s /opt/node-$NODE_VERSION-linux-x64/bin/node /usr/local/bin/node
ln -s /opt/node-$NODE_VERSION-linux-x64/bin/npm /usr/local/bin/npm
cd /home/vagrant
rm node-$NODE_VERSION-linux-x64.tar.gz
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment