Upgrading Node and its dependencies when Upgrading Ghost Install Script

SYSTEM INFORMATION
OS type and version Rocky Linux 9.1
Virtualmin version 7.7 Pro

I just realized that @Ilia —in a reply to an earlier related question—hinted at additional steps I should be taking when updating Ghost (installed via Virtualmin’s Install Scripts):

I originally expected that since the Ghost Install Script installs Node, that if I then clicked Upgrade for the Ghost Install Script (when updates are available), that it would also upgrade the underlying Node version and its dependencies if needed.

I’ve realized that this is not the case, and that I have outdated versions of Node on several of my older Ghost (5.26.3) installs (Node 16.19.0 instead of Node 18.15.0).

I was able to find my way to /home/domain/public_html/bin/node so that I could check the Node version, but I’m not sure (this really feels like a newbie question!) how to update Node and its dependencies for a specific website installed with the Ghost Install Script.

I would love to know how to do this, since Node 16 is reaching its rather-early EOL soon!


One other somewhat related thing I noticed that it seems @Ilia might like to know: I decided to delete a couple of test Ghost websites I’d set up. Even though I planned to remove the entire Virtual Server, I first uninstalled the Ghost Script in the Install Scripts area, and then removed the entire Virtual Server.

Surprisingly, the service files get left behind (ghost-domain-port.service). Even after a server reboot, these service files were still set up to start on boot (referring to ports now in use on more recently setup domains). Harmless I’m guessing, since they were failing (simply generating errors in the system log). I removed them manually.

Thank you kindly for your thoughts on how to keep my Ghost installs up-to-date, now that I realize upgrading via the Ghost Install Script doesn’t upgrade Node and its dependencies!

No idea about Ghost :person_shrugging:t2:
but Nodejs versions (esp. where you require multiple versions available on a server) use NVM (Node Version Manager)

Yes I’m familiar with using NVM in a local dev environment, but these Node installs on the server are created by Virtualmin Pro’s Ghost Install Script, and so ideally I’d like to know the recommended Node/NPM upgrade path for my Ghost Installs from @staff

One of the reasons I upgraded to Virtualmin Pro on this server was to use the Ghost Install Script. I’d expected that Upgrading via its Install Script would also update underlying pieces (including Node and its dependencies), but I’ve realized that’s not the case.

Hello,

This won’t happen automatically. Also, please note that Node.js 16 is still recommended version based on Ghost documentation. Node.js version 18 yet listed as supported.

That is something unexpected. I cannot reproduce it on my Node.js instance. If I uninstall Ghost instance, systemd service file is also removed. What is the content of those files that are left look like? Perhaps, it is an old init script?

Ideally, yes! However, running unattendent upgrades like this can be risky and easily break the whole system. Node.js, Ghost and all of its modules have a very fast development pace. I would suggest making upgrades (if needed) manually. Nevertheless, we could add an option to upgrade Node.js and modules to Virtualmin UI, however, as I already mentioned it could be risky…

Yes, you’re right, Node 16 is still the recommended version. However when I recently setup a new Ghost site via Install Scripts, it installed Node 18 automatically. Also there is a slightly newer version of Node 16 that I could update on the two older Ghost sites that I set up via Install Scripts.

The reason I first posted here (especially in the Newbies forum!) is that I really don’t know how to upgrade Node manually in these cases? I’ve always used a package manager locally, and for the couple non-Ghost Node sites that I have in Virtualmin, I use the Install Scripts interface for upgrading Node.js whenever there’s a new version available.

What command do I issue in order to upgrade Node manually for a specific Virtual Server? I did find Node inside /home/domain/public_html/bin/node so I’m guessing I need to be there, and then run a command… or? I kind of wish that the Install Scripts area on these Ghost websites would show Node as an option to Upgrade as well as Ghost :slight_smile:

I removed the files, so I don’t know what they looked like inside. But I’m assuming they had the usual Ghost systemd service content, since the filenames were of exactly the same form as the Ghost systemd service files (ghost-domain-port.service). I don’t know why they got left behind, since these were Ghost sites I’d just set up lately with Install Scripts, and I first uninstalled Ghost via Install Scripts for each, before deleting each Virtual Server.

Just to add (if it helps), the contents of the systemd files in question generated these errors in the logs (how I even noticed them in the first place):

systemd[752]: ghost-[virtual-server-subdomain]-3002.service: Failed at step STDOUT spawning /home/[virtual-server]/domains/[virtual-server-subdomain]/public_html/node_modules/.bin/ghost: No such file or directory

No surprise that there is no such file or directory, given I deleted the whole Virtual Server after uninstalling Ghost via Install Scripts. These were both subdomains (“sub-servers”, in Virtualmin), if that matters at all? This is a fresh server with Rocky Linux 9.1, a fresh Virtualmin Pro, and just a handful of sites, so I was a little surprised to see any errors in the logs, and to find those orphaned files originally put there by Ghost’s Install Script.

If you’re making a minor version upgrade, i.e. within a major version 16, e.g. 16.19.0 to 16.20.0, I think, you don’t need to use any commands just download a newer Node.js binary from official website and replace it in public_html/ghostblog/bin directory, later restarting corresponded Ghost systemd service.

However, upgrading a major Node.js version, i.e. 16 to 18 may (most likely) require re-building dependencies previously built for that specific Node.js version by running ghost update [version] --force. For that purpose always use official Ghost documentation and community to look for help, as this is not our sphere of expertise.

No surprise that there is no such file or directory, given I deleted the whole Virtual Server after uninstalling Ghost via Install Scripts.

In fact, if you delete virtual server without uninstalling Ghost first, those systemd service will be left behind. @Jamie, should we address it, and also delete dependent systemd service files for installed scripts when virtual server is deleted?

Just a quick note to say that those files got left behind, even though I uninstalled Ghost first (which I did with the thought it’d clean up any files before I deleted the Virtual Sub-Server).

Thanks so much for pointing me in the right direction with respect to the Node/NPM upgrades! I downloaded the appropriate binaries and shall try that upgrade soon.

Hmm, I ended up running into problems trying to upgrade my Ghost install from Node 16.19.0 to Node 16.20.0 by simply replacing the binary.

I downloaded what I took to be the appropriate Node binary from nodejs.org’s prior releases page: node-v16.20.0-linux-x64.tar.gz (FYI my kernel/CPU is: Linux 5.14.0-162.23.1.el9_1.x86_64 on x86_64)

I then stopped my Ghost website’s systemd service, backed up the original Node binary located in /home/domain/public_html/bin/node and then replaced that binary with the fresh Node binary, checking the permissions and owner to ensure those matched the one I was replacing.

I then tried to restart the corresponding Ghost systemd service, but it failed with these errors:
ghost-domain-3000.service: Control process exited, code=exited, status=1/FAILURE
ghost-domain-3000.service: Failed with result 'exit-code'

When I replaced the new Node 16.20.0 binary with the 16.19.0 backup I’d made, the Ghost service again started up just fine.

Am I missing something obvious? I just want to ensure that I’m able to keep all the packages on my server up-to-date, to ensure no security problems in the future. Thank you!

Whew, I managed to upgrade Node from v16.19.0 to v18.16.0! I really wanted to make it work, since the EOL date for Node 16 was brought forward to 9/11/2023 (because of OpenSSL 1.1.1).

Here’s what I did, in case anyone else wishes to do this. Note I’m running Ghost v5.46.0 currently. I probably did this the long way in some respects, but it worked!

So I’ve noticed that whenever I create a fresh Ghost install using Install Scripts, the latest Node is downloaded along with it. I setup a quick subdomain and installed a fresh Ghost (v5.46.0) via Install Scripts, which brought Node v18.16.0 with it.

So then I stopped the Ghost server via Install Scripts on my main domain, in order to run these commands, copying all the Node-relevant files over from the fresh subdomain (note that I also backed up all the Node v16 files/folders first):

sudo cp -rp /home/[domain]/domains/[subdomain]/public_html/bin/node /home/[maindomain]/public_html/bin/node
sudo cp -rp /home/[domain]/domains/[subdomain]/public_html/lib/node_modules /home/[maindomain]/public_html/lib/node_modules
sudo cp -rp /home/[domain]/domains/[subdomain]/public_html/include/node /home/[maindomain]/public_html/include/node
sudo cp -rp /home/[domain]/domains/[subdomain]/public_html/node_modules /home/[maindomain]/public_html/node_modules
sudo cp -rp /home/[domain]/domains/[subdomain]/public_html/package-lock.json /home/[maindomain]/public_html/package-lock.json

sudo chown -R [maindomain]:[maindomain] /home/[maindomain]/public_html/bin/node /home/[maindomain]/public_html/lib/node_modules /home/[maindomain]/public_html/include/node /home/[maindomain]/public_html/node_modules /home/[maindomain]/public_html/package-lock.json

The next bit took me some sussing out, involving carefully examining the ghost-[maindomain].com-3000.service systemd file found in Virtualmin under System > Bootup and Shutdown.

Long story short, I ran these commands next, while logged in as the [maindomain] owner. First this one, (taken directly from the systemd file), otherwise nothing works (instead returning error /usr/bin/env: ‘node’: No such file or directory):

PATH=/home/[maindomain]/public_html/bin:/home/[maindomain]/public_html/node_modules/.bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin

That fixes the Node environment issue. I was now free to run:

ghost doctor

That gave me the following errors:

1) SystemError

Message: The directory /home/[maindomain]/public_html/ is not readable by other users on the system.
This can cause issues with the CLI, you must either make this directory readable by others or install node and Ghost-CLI in another location.


2) Checking binary dependencies

Message: The installed node version has changed since Ghost was installed.
Help: Run ghost update 5.46.0 --force to re-install binary dependencies.

Running ghost update 5.46.0 --force doesn’t work though, because of that SystemError permissions issue above (the directory not being readable by other system users). The magical fix is to run this command next (the additional --no-setup-linux- flag is also found in the systemd file for starting Ghost, and basically skips a couple checks so that everything runs):

ghost update 5.46.0 --force --no-setup-linux-

Everything ran perfectly after that, and this time, when I went back to my main domain’s Install Scripts page in Virtualmin, and tried Starting the Ghost server again, it all worked, happily running on Node v18.16.0 (easily checked by running node -v).

I’m pretty excited I got it working. Maybe it wasn’t necessary to set up a subdomain and fresh Ghost install just to pull all these files. Maybe I didn’t need to copy over all those Node files/folders that I did. But it is working happily now :slight_smile:

Oops, realized that last command was a copy/paste mistake, should be:

ghost update 5.46.0 --force --no-setup-linux-user

Just noticed while using these instructions to update Node v16 to v18 on my other Ghost site. Figured I should update (couldn’t edit the above any longer), in case anyone comes by looking to do what I did!

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.