Updating systemd node version

Upgrading node and uninstalling old version does not update what Ghost is using in systemd

Ghost one-click from DigitalOcean is still using Node 16.17.0
Upgrading to latest 18.xx version and removing 16.17.0 via nvm

Checking system Node.js version - found v16.17.0

Question: Where is Ghost’s systemd config located?

/lib/systemd/system/

Thanks
I had looked at that previously but did not see anything obvious to change.

[Unit]
Description=Ghost systemd service for blog: www-rvingpros-com
Documentation=https://ghost.org/docs/

[Service]
Type=simple
WorkingDirectory=/var/www/ghost
User=997
Environment="NODE_ENV=production"
ExecStart=/usr/bin/node /usr/bin/ghost run
Restart=always

[Install]
WantedBy=multi-user.target

Looking for info on forcing an update to NODE_ENV=production

What does /usr/bin/node --version return?

And dpkg -l 'node*'?

You should not modify files under /lib in any case-- that directory is reserved for vendor packages.

If want to customize this file, you can install a replacement in /etc/systemd/system/ and it will be prioritized.

Even better, search for “drop-in” in this file: systemd.unit

You can create a “drop-in” directory under /etc/systemd/system and add a config file that overrides just the values you want to modify from /lib.

This way, your changes would survive an upgrade or re-install of Ghost.

Why would you want change this value in production to something else?

root@ghost2:~# node -v
v18.18.0

root@ghost2:~# /usr/bin/node --version
v16.17.0

root@ghost2:~# dpkg -l 'node*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version                  Architecture Description
+++-==============-========================-============-======================>
ii  nodejs         16.17.0-deb-1nodesource1 amd64        Node.js event-based se>
un  nodejs-dev     <none>                   <none>       (no description availa>
un  nodejs-doc     <none>                   <none>       (no description availa>
un  nodejs-legacy  <none>                   <none>       (no description availa>

I stated this poorly… looking to force the use of latest 18.xx as version used in NODE_ENV=production

Thanks.

I missed on the first pass your mention of nvm as your upgrade method.

As you can see from testing some system versions, Node 16 is still installed and /usr/bin/node – the one that Ghost uses – uses is still version 16.

NVM is not really meant as a system package manager because it works by modifying environment variables that are only set in your current shell-- and those changes don’t apply to systemd units.

First, I would question why you are upgrading Node, since Node 16 is supported and is working fine.

But if you want to upgrade Node, I would recommend the n version manager, which you can install from NPM. To use it, the syntax would be like sudo n 18.

It will install a new node in /usr/local/bin/node

From there, you can use a method I described previously to create a new Ghost systemd unit file that replaces /usr/bin/node with /usr/local/bin/node OR you can remove /usr/bin/node and symlink it to /usr/local/bin/node. If you do that, you are messing a file with managed by the nodejs package, and it may complain if you uninstall or upgrade the nodejs package later.

Oh look, there’s some official documentation about using nvm:

It seems to recommend that’s OK to use nvm, but to symlink the Node binary that NVM installs to /usr/bin/node, but I would recommend just using n instead.

Thanks for the education on NVM vs n. I understood this much differently.
The hoops/steps to change Node version are significant. I am thinking it would be better or at least a bit easier to deploy new server that is already using the desired Node version then migrating the Ghost site to new server.

Yes, 16 is working fine but 18.xx is current supported version. Whether one upgrades Node now or later eventually it would be less of an optional thing. Upgrading is a certainty at some point. May as well learn the in and outs of doing so now.
FYI: I think Ghost folks have updated DigitalOcean one-click but the old version is still being deployed as of a couple of days ago.

BTW: Difficulty udpgrading Node is what lead to Installation Errors Using Official Doc

@PhilH,

@RyanF pointed out to me that Node has updated official documentation on how to upgrade Node using operating system packages:

This is a way to upgrade from Node 16 to 18 that may be even better than using either nvm or n for the task.

And you are right-- now that Node 16 is being EOL’ed, that’s a good reason to upgrade!

@markstos and @RyanF Thank you!

Started a fresh instance of Ghost One-click but the installer is now installing v18.17.1
The instructions from Nodesource were a snap for upgrading to Node v18.18.1. Should make keeping Node current a snap.

Maybe post or tag would be helpful for others. DigitalOcean Ghost 1-Click

2 Likes