By Andrew SB
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?
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!
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 https://deb.nodesource.com/setup_4.x | 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
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.