How to Easily Update to Node v4 for Ghost

Post cover image

Ghost recently announced that Node 0.10 will no longer be supported on October 1st. If you are running your Ghost blog on DigitalOcean or through some other self host, you will need to upgrade to Node v4.

Here is how you can do that:

Note: this may not be the same for all environments, but will work on the one-click DigitalOcean Ghost installs and should work on other Ubuntu installs as well.

  1. Check to see which Node version you are running

    node -v
  2. If it returns with any version that isn't Node 4.x.x, then continue. If you already have Node v4, then your fine and don't need to update!

  3. Check where Node is installed

    which nodejs
  4. If the following command returns /usr/local/bin/node and not /usr/bin/node then that means you have an older version of the DigitalOcean droplet. Please make a note of this for a later step.

  5. Remove current Node.js

    sudo apt-get purge nodejs
  6. Grab the Node v4 install source

    curl -sL | sudo -E bash -
  7. Update apt-get resources

    apt-get update
  8. Upgrade your currently installed packages

    Note: this will upgrade your installed resources. So, if you dont want to do this because you are using older resources for other stuff, then skip this step

    apt-get upgrade
  9. Install Node.js

    apt-get install nodejs
  10. Move to the Ghost folder

    cd /var/www/ghost/
  11. Stop Ghost

    service ghost stop
  12. Remove installed Node modules from last Node version

    rm -rf node_modules
  13. Reinstall Node modules

    npm install --production

    Note: Sometimes on the $5 DigitalOcean droplets this command can fail because it runs out of usable memory. You will know if it failed because it will only go a few lines (should go like 100 lines normally), and Ghost won't then startup because it says it is missing packages.

    To fix this, you need to add some swap memory to your droplet. This is pretty straightforward, just follow the instructions here. Just copy and paste their commands and then run steps 10 and 11 again.

  14. Set permissions correctly

    chown -R ghost:ghost ./*
  15. If you have the older version of the droplet as figured out from step 3, you need to do the following. If not, skip to step 16:

    Edit the init file:

    vim /etc/init.d/ghost

    Replace all instances of /usr/local/bin/npm with /usr/bin/npm

    Delete /usr/local/bin/npm and /usr/local/bin/node

  16. Start Ghost

    service ghost start

    Note: Again, if Ghost doesn't start, check the note in step 11.

That is it! You removed Node 0.10 and installed Node v4 and should be good to for a long time. If you have any trouble, feel free to leave a comment or hit us up on twitter!