Ghost won't start. Mismatched Node version (?) after mysql issue

The node mismatch error has come up a couple of times recently, so let’s look at how it’s actually calculated.

There are a couple places where the message could be generated.

One reference to it is here:

That’s part of Ghost Doctor. In that case, it appears to be parsing the path to node out of the systemd service file, and then calls that copy of Node with --version to check the version.

You can check this version yourself using:

grep node /lib/systemd/system/*ghost*

On my Linux server, these all point to /usr/bin/node

At the same time, Ghost doctor calculates “your current version of node” by checking the version of node that ghost doctor is running as.

From looking the source of /usr/bin/ghost, I can see that it looks up the version of node to use by using:

/usr/bin/env node

If you want to find out what version of Node would be used that case, you can use which node to check.

So what we have learned about the mismatch can happen?

systemd doesn’t consult the environment to decide which version to run. It always a fixed path, like /usr/bin/node. But ghost doctor runs a version of node that is influenced by the environment, namely $PATH.

What about using nvm and n as Node version managers for Ghost?

nvm is sure to cause problems because it works by modifying your environment variables, so it will affect which Node is used by ghost doctor, but not by systemd. Not good.

n is better as a Node version manager, but where does it actually installed Node? According to the docs, it will the Node versions into /usr/local, meaning /usr/local/bin/node. This is better than nvm because at least it’s not using environment variables, but notice that this is not the same as /usr/bin/node, so a mismatch is still possible.

If you want to use a version of Node that’s not supplied by the OS, after you have installed n to install a version of Node into /usr/local/bin, you could uninstall the OS nodejs package, and then create a symlink from /usr/local/bin/node to /usr/bin/node that would sync the version installed by n with the location that systemd is looking for Node:

ln -s /usr/local/bin/node /usr/bin/node

Are there better solutions to avoid Node mismatch errors?

  1. If you already have Node 16 installed, don’t install Node 18-- Node 16 is supported and works fine!
  2. This situation could be considered a bug in Ghost doctor. If Ghost is hardcoding /usr/bin/node in the systemd files, when the ghost CLI is installed, it should do the same thing-- if it did that, getting a version mismatch would be impossible.
1 Like