Node.js & less on Media Temple Grid

Maybe I’m crazy, but I wanted to install Node.js in a (gs) shared hosting environment so that I could compile and save small changes to my LESS-based stylesheets via SSH without having to maintain a local working copy. That’s right. I said it. I change files in a live environment sometimes, and there’s nothing wrong with that! Anyone who opines to the contrary in the comments below will be swiftly dealt with.

This how-to is based on the great work of [Ian Tearle and his commenters](http://iantearle.com/blog/media-temple-grid-and-nodejs).

### Preparation

Get your Media Temple Grid Service site number. If you don’t know your site number, see [this Media Temple support page](https://kb.mediatemple.net/questions/268/What+is+my+site+number%3F#gs). For this tutorial, we’ll use the **123456** as an example.

First, let’s to prepare the shell environment to recognize executables in the new directories we’re going to create. Create or edit *~/.bash_profile* and add the following lines:

PATH=/home/123456/data/opt/:$PATH
PATH=/home/123456/data/node_modules/.bin/:$PATH
export PATH

Save the file and exit, then source *~/.bash_profile* to reflect the changes without logging out and back in:

$ . ~/.bash_profile

### Building Node

Now let’s [grab Node.js from GitHub](http://github.com/joyent/node):

$ git clone https://github.com/joyent/node.git
$ cd node
$ mkdir -p /home/123456/data/opt
$ ./configure --prefix=/home/123456/data/opt/
$ make && make install

If all goes well (that make can take a while), you should now have a fully-functioning Node.js installation. Test it out by typing `node -v`. If you see a version number and not an error, you’re in business!

### But wait! There’s less!

Now it’s time to download and install **less**.

$ cd ~/data/
$ npm update
$ npm install less

This will install the **lessc** binary in the *~/data/node_modules/.bin* directory which we added to our $PATH. The installation may fail. If it does, just try running it again a few times until it works.

If all goes as well for you as it did for me, you should now be able to use **lessc** from anywhere within your jailed shell environment!

3 Comments

  • Tyler Smith says:

    I have several domains on my GS already running on php.
    I’m new’ish to node and am curious how I can get this running on only one domain and not effect the other sites I host.

  • Linuxtrek says:

    PATH=/home/123456/data/opt/:$PATH

    This should have /home/123456/data/opt/bin.

  • Dave says:

    Almost 3 years later…

    Having trouble making this work. Tried a couple times but node -v gives “node command not found”. Tried to do some troubleshooting, but getting nowhere other than might be issue with g++?

    I Read on Ian Tearle’s article a comment by a Media Temple employee saying they don’t like you having node at all.

    Does this still work for you? Any help is appreciated!

Leave a Reply

Your email address will not be published. Required fields are marked *