Skip to content

Instantly share code, notes, and snippets.

@elmarcoh
Created December 10, 2012 14:38
Show Gist options
  • Save elmarcoh/4250901 to your computer and use it in GitHub Desktop.
Save elmarcoh/4250901 to your computer and use it in GitHub Desktop.
Install node & npm in virtualenv
#!/bin/sh
#
# This script will download NodeJS, NPM and lessc, and install them into you Python
# virtualenv.
#
# Based on a post by Natim:
# http://stackoverflow.com/questions/8986709/how-to-install-lessc-and-nodejs-in-a-python-virtualenv
NODEJS="http://nodejs.org/dist/v0.8.3/node-v0.8.3.tar.gz"
# Check dependencies
for dep in gcc wget curl tar make; do
which $dep > /dev/null || (echo "ERROR: $dep not found"; exit 10)
done
# Must be run from virtual env
if [ "$VIRTUAL_ENV" = "" ]; then
echo "ERROR: you must activate the virtualenv first!"
exit 1
fi
echo "1) Installing nodejs in current virtual env"
echo
cd "$VIRTUAL_ENV"
# Create temp dir
if [ ! -d "tmp" ]; then
mkdir tmp
fi
cd tmp || (echo "ERROR: entering tmp directory failed"; exit 4)
echo -n "- Entered temp dir: "
pwd
# Download
fname=`basename "$NODEJS"`
if [ -f "$fname" ]; then
echo "- $fname already exists, not downloading"
else
echo "- Downloading $NODEJS"
wget "$NODEJS" || (echo "ERROR: download failed"; exit 2)
fi
echo "- Extracting"
tar -xvzf "$fname" || (echo "ERROR: tar failed"; exit 3)
cd `basename "$fname" .tar.gz` || (echo "ERROR: entering source directory failed"; exit 4)
echo "- Configure"
./configure --prefix="$VIRTUAL_ENV" || (echo "ERROR: configure failed"; exit 5)
echo "- Make"
make || (echo "ERROR: build failed"; exit 6)
echo "- Install "
make install || (echo "ERROR: install failed"; exit 7)
echo
echo "2) Installing npm"
echo
curl http://npmjs.org/install.sh | sh || (echo "ERROR: install failed"; exit 7)
echo
echo "3) Installing lessc with npm"
echo
npm install less -g || (echo "ERROR: lessc install failed"; exit 8)
echo "Congratulations! lessc is now installed in your virtualenv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment