Moving Ghost to an updated Node version, and clearing the Yarn cache

I was recently trying to upgrade this blog from Ghost version 5.44.0 (very old, and had some security issues) to the latest release of Ghost. When I'd tried to upgrade previously (before I knew about the security issue), my attempts to upgrade failed with a number of errors.

This post is a "quick fix" note as I was stuck for answers. Hopefully this helps some others. Note that there is no warranty of any kind associated to this post. I recommend you have a backup before you follow any steps outlined here.

A note on my environment

It should be noted that my environment isn't officially supported by Ghost:

  • I'm using Debian rather than Ubuntu
  • I'm using MariaDB rather than MySQL

This is because I was installing my blog onto an existing server. Be mindful that if you are not running Ghost on a supported configuration that you may receive several "well you're not supported" type responses on the Ghost forum.

Supported Node versions

As of publishing this post, Node version 18 is supported but version 20 LTS is recommended. For the time being I'm staying on Node version 18.

Details of the supported Node versions can be found here.

Update failures - Yarn issues

While attempting the ghost update command I was seeing errors like the below:

Message: Command failed: yarn install --no-emoji --no-progress
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@^2.29.1"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@2.29.1"
warning Resolution field "moment@2.24.0" is incompatible with requested version "moment@^2.27.0"

I don't know much about Node so this had me confused - I didn't entirely know what yarn was for a start! After a bit of research I was being advised to clear my "yarn cache", so I figured I'd give that a try.

I began by getting yarn installed globally, so I could easily run it from my command line:

$ sudo npm install -g yarn

Trying to clear the yarn cache with yarn cache clean was taking ages and had the CPU sat at 100% usage. Research online showed that was a common problem, had been for years, and that the advice was to just delete the cache directory instead.

So I investigated the location of my "yarn cache" using yarn cache dir. I renamed the directory, so I could move back if necessary, and tried to upgrade again.

The update was successful but then I noticed an old Node version was in use:

Warning: Ghost is running with node v14.21.3.
Your current node version is v18.18..

Moving Ghost to use the updated Node version

After a bit of digging I found that I somehow had multiple Node versions installed on my system:

jonathan:~$  whereis node
node: /usr/bin/node /usr/local/bin/node /usr/include/node /usr/share/man/man1/node.1.gz
jonathan:~$ /usr/bin/node --version
v14.21.3
jonathan:~$ /usr/local/bin/node --version
v18.18.2
 

I'm not sure how I ended up with this mess (and I don't have Node Version Manager, nvm installed), but it's clear that I needed to tell Ghost to move to version 18. I tried Googling "move Ghost to updated Node version" and "change Node version used by Ghost", all to no avail. The Ghost forums contained people with my problem, but there wasn't anyone sharing the answer.

Eventually I remembered that Ghosts initiation script likely had the path to Node in it. At the same time Andee messaged me the same thing, so that was reassuring. Fortunately, the last time I had a problem with Ghost I blogged about it here.

A quick edit of /etc/systemd/system/ghost_localhost.service, a reload of the service definitions using sudo systemctl daemon-reload, and a restart of the ghost_localhost via sudo service ghost_localhost restart and my Ghost install was running correctly again.

In summary

  • Clear the yarn cache by deleting the cache directory that you can find with yarn cache dir
  • Edit your service definition at /etc/systemd/system/ghost_localhost.service is using the latest supported Node version that you have installed (find Node versions with whereis node and then using /path/to/node --version to find the latest one)
  • Reload the service definitions with sudo systemctl daemon-reload
  • Restart the service with sudo service ghost_localhost restart

Banner image, the Ghost logo, from https://ghost.org/design/.