How to upgrade Node.js on older Ghost Droplets?

July 22, 2016 815 views
Ghost Node.js One-Click Install Apps

Ghost blogs built with DigitalOcean's One-Click application before February 11th, 2016 came with Node.js built from source. More recent ones install it using the Nodesource Apt repository. These can update Node.js by simply running:

  • sudo apt-get update
  • sudo apt-get upgrade

How can you update the version of Node.js to the most recent LTS version on an older Ghost Droplet?

1 Answer
asb MOD July 22, 2016
Accepted Answer

There are multiple methods you can use to update Node.js on your older Ghost Droplet. Here I'll explain how to do it using the Nodesource Apt repository. Tools like n or nvm could also be used, but I've chosen to use the repository in order to be consistent with how newer Ghost Droplets are created and so that you can receive ongoing updates to Node.js via your package manager as you apply normal updates.

First, confirm that you are using an older version that was installed from source. Run:

  • which nodejs

If the output is /usr/local/bin/node as opposed to simply /usr/bin/node, then you are using an older version.

To add the Nodesource repository and install the latest LTS version of Node.js, run:

  • curl -sL | sudo -E bash -
  • sudo apt-get install -y nodejs

After installation completes, verify that you have an up-to-date Node.js by running:

  • /usr/bin/node --version

Next, we'll need to update the Upstart script that is used to run Ghost. Temporarily shutdown Ghost with the command sudo service ghost stop Now, edit the file /etc/init.d/ghost and replace all instances of /usr/local/bin/npm with /usr/bin/npm When you are done, it should look like:

description "Ghost: Just a blogging platform"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

# If the process quits unexpectedly trigger a respawn

setuid ghost
setgid ghost
env NODE_ENV=production
chdir /var/www/ghost

exec /usr/bin/npm start --production

pre-stop exec /usr/bin/npm stop --production

Now, restart Ghost and confirm it is running as expected:

  • sudo service ghost start

Finally, after you've made sure that everything is successfully installed and running, you can delete both /usr/local/bin/npm and /usr/local/bin/node

Have another answer? Share your knowledge.