Question

How to upgrade Node.js on older Ghost Droplets?

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:

  1. sudo apt-get update
  2. sudo apt-get upgrade

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


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
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:

  1. 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:

  1. curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
  2. sudo apt-get install -y nodejs

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

  1. /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
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:

  1. 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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel