Node.js on Dreamhost
**** Updated: 8/11/2013
There is no reason to compile node.js on your server anymore. Just use apt-get.
**** Updated: 1/26/2012
There are a few guides to installing node.js on Dreamhost, but none that take you from start to finish deploying a node.js server. This guide will attempt to do just that. Everything should work on with a shared server, but I would highly recommend a VPS.
In this guide we will:
- Install Node.js
- Install npm
- Install forever
- Start a node app as a daemon
- Add a cron job to keep it running
So lets get started. Make a download dir to store the node source and download it.
mkdir downloads cd downloads git clone https://github.com/joyent/node.git
Find the latest version
This will list all of the tags in the repository. You can checkout any version from this list. Keep in mind that version that start with an odd number are not release versions. So v0.4 was the last release before v0.6 and v0.5 was not for production.
git checkout v0.6.8
Now we make a local bin, configure, compile and install node
mkdir -p ~/usr/local/bin ./configure --prefix=~/usr/local make make install
We must then add the new bin to the path variable
export PATH=$PATH:$HOME/usr/local/bin echo "export PATH=$PATH:$HOME/usr/local/bin" >> ~/.bashrc echo "export PATH=$PATH:$HOME/usr/local/bin" >> ~/.bash_profile
Node should now work. This will give you the version of node that is installed and should match the version we checked out earlier.
Next we need the node package manager npm. This will download and install it.
curl http://npmjs.org/install.sh | sh
Lets check that it installed
Now that everything is installed we need a way to deploy node apps. For that we will use forever.
npm install -g forever
To start node as a daemon with forever run
forever start path/to/server.js
Forever will keep the node daemon running as long as the server stays up. We need one more thing to restart the node daemon if the server is restarted. To do this we will add a cron job to start the node daemon after the server is restarted.
@restart path/to/forever start path/to/server.js
You can get the path to forever by running
This should get you started. If you have any questions or run into problems leave a comment.