Ghost update with NVM

Problem

Maintaining a ghost blog on its own VM requires diligent system updates and maintenance. Today, when I updated ghost using ghost-cli, it threw a message that I need to update compatible node version. My node was v14 and the new ghost update requires the version 18.

While there are instructions for updating Node through the binary distribution from nodesource, I opted for a more straightforward approach using the Node Version Manager (NVM). NVM facilitates seamless Node version switching, making it a preferable choice for managing the update.

While there is an instruction for updating Node through the binary distribution from nodesource, I opted for a more straightforward approach using the Node Version Manager (NVM). NVM facilitates seamless Node version switching, making it a preferable choice for managing the Node update.

How to Update

First, install NVM following the link correctly. And it will create .nvm folder under the username responsible for running your Node applications. My case is ghsot-mgr (it can be any name). Confirm your NVM node path, /home/ghost-mgr/.nvm/versions/node/v18.12.1/bin/node. Next, install 'ghost-cli' following the instruction here. Ghost-cli will appear under /home/ghost-mgr/.nvm/versions/node/v18.12.1/bin/ghost. I had a hiccup when I install ghost-cli. It did not pick up my current node path. So, I should npm cache clean and tried it again.

Caveat & How to Handle it

But there is a caveat that you have to manually maintain the current node version in the systemd service file (/lib/systemd/system/your-ghost-service-file). The systemd file automatically resurrects your node applications when the server restarts. When you update to a new node version later, you should update this file accordingly.

I change the line of ExecStart,

from

ExecStart=/usr/bin/node /usr/bin/ghost run

to

ExecStart=/home/ghost-mgr/.nvm/versions/node/v18.12.1/bin/node /home/ghost-mgr/.nvm/versions/node/v18.12.1/bin/ghost run

This will make your node run on your NVM node version. So, now I run the latest ghost version on Node 18 version.

I got an inspiration for this implementation from this link.

I hope this helps others manage Ghost and node versions. Happy blogging!