Upgrade nodejs and ghost

I had no idea this was going to be such a monumental pain. I happened to be looking at the the versions of ghost, and possibly other ways of running the blog; and decided to spend the afternoon upgrading to the latest version of ghost. Interestingly I happened to also look at the versions of nodejs that were supported for ghost. I was out of date there. So what follows took me most of the afternoon to piece together. It seems pretty simple, but given that the npm install time on a RaspPi (well over half an hour) it still took a while.

// Get up-to-date node from herokuapp.com
wget http://node-arm.herokuapp.com/node_0.10.36-1_armhf.deb
dpkg -i node_0.10.36-1_armhf.deb

This is a great repository for recent builds of nodejs. For more info see here. Particularly they also have viable builds for 0.12.* (which ghost doesn't currently support, but hopefully will in the future).

Next up we need to get the latest ghost.

// Get up-to-date ghost from ghost.org
wget http://ghost.org/zip/ghost-latest.zip
unzip -uo ghost-latest.zip -d ghost-0.6.4

Move your content from the previous ghost install to the new one. This recipe comes from here.

cd ghost-0.6.4
rm -rf content
rm -rf config.example.js
cp -R ../ghost-0.5.0/content .
cp -R ../ghost-0.5.0/config.js .

Now we need to ensure that all the new packages are in place to run node.

npm install --production --unsafe-perm

The --unsafe-perm is needed to install sqlite which is going to need to rebuild from scratch. This requires access to /root/.node-gyp but node-gyp will otherwise run as a different user and NOT have access to the location. This stops the build from scratch working (without --unsafe-perm)

The final tweak is that ghost ships with bcryptjs as its password mechanism. This is far too slow to be usable. We need to convert to using bcrypt instead. To do this we need to install it and change the node code.

npm install bcrypt --production --unsafe-perm
emacs core/server/models/user.js
// Replace bcryptjs with bcrypt
// AND remove the user.js~ file

Finally we need to ensure that the all the blog code and content is owned by the right unix user.

chown -R ghost.ghost *

OK - at this point we should be complete. Test using

npm start --production

And then go back to supervisorctl and restart the ghost service having pointed latest at the new location.

One nice new feature of ghost is the ability to export the whole blog as JSON, which allows a more complete backup of the content and doesn't leave you feeling so worried about the content folder.