I have been using Ghost for sometime on my VPS running Ubuntu 16.04. I am also using the VPS for hosting my personal nodejs applications. Recently, I moved to nvm and after that I have been unable to start my Ghost instance. ghost start completes silently but the service doesn’t start and the error logs of the service shows the following error
Failed at step EXEC spawning /usr/bin/node: No such file or directory
Yes, there is no file node inside /usr/bin. I have nvm installed under /root/.nvm. I realise that Ghost recommends node to be installed globally. But I have applications running already. Is it possible to do anything to bring up my blog without changing node configuration, so that my applications doesn’t go down?
The problem is that since you initially started without NVM Ghost got to know only one route to your node bin. And now your node installation is somewhere else. To know this type nvm ls to list your node installations:
Mine are:
dev@example-master:~$ nvm ls
v8.12.0
-> v10.12.0
system
I use v10 for my Node.js app and v8 exclusively for Ghost. So whenever I want to make any config I change my NPM version to v8 by doing:
dev@example-master:~$ nvm use 8
Now using node v8.12.0 (npm v6.4.1)
Now finally to know where your bin is just type:
dev@example-master:~$ nvm which 8
/home/dev/.nvm/versions/node/v8.12.0/bin/node
This route: /home/dev/.nvm/versions/node/v8.12.0/bin/node is the one you have to add to your echo $PATH or as a last option re-install Ghost while using nvm use 8.
I checked my $PATH variable and it currently has /home/myusr/.nvm/versions/node/v8.11.4/bin as well as usr/bin. I have even tried adding /home/myusr/.nvm/versions/node/v8.11.4/bin/node in my path but to no avail. I am getting the same error.
Does Ghost sets up some configuration as to which path to use. Because as you pointed out, when Ghost was installed, I had node installed and Ghost probably set up that path as the path to use and now it is not looking for any other paths. If there is some configuration I can change it to look for node in the correct path.
You can clearly see in your picture that you are missing the ghost-cli package inside your global node-modules for the desired node version. Which I believe is the main reason this is not currently working for you. This happened to me at first because I had it installed in the other version of node.
Remember that when using NVM all node-modules live in separate folders. You can check which packages you have in each version by going to:
cd ~/.nvm/versions/node/[node-version-here]/lib/node_modules/
I have installed Ghost CLI (1.2.1 since that is what I had installed initially) and after that I tried running ghost start. Now, for the first time, I am getting an error before the service starts. The error is similar to the error in the previous screenshot
/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/node_modules/yargs/yargs.js:1057
else throw err
^
Error: failed
at module.exports.sync (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/node_modules/execa/index.js:303:26)
at handleShell (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/node_modules/execa/index.js:105:9)
at Function.module.exports.shellSync (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/node_modules/execa/index.js:312:43)
at SystemdProcessManager.isRunning (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/extensions/systemd/systemd.js:61:19)
at Instance.running (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/lib/instance.js:119:27)
at StartCommand.run (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/lib/commands/start.js:28:22)
at Function._run (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/lib/command.js:198:48)
at Object.handler (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/lib/command.js:117:22)
at Object.runCommand (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/node_modules/yargs/lib/command.js:226:22)
at Object.parseArgs [as _parseArgs] (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/node_modules/yargs/yargs.js:970:30)
at Object.parse (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/node_modules/yargs/yargs.js:538:25)
at Object.run (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/lib/bootstrap.js:165:14)
at Object.<anonymous> (/root/.nvm/versions/node/v8.11.3/lib/node_modules/ghost-cli/bin/ghost:14:11)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
I don’t know if it matters but I got an error while installing Ghost CLI
You can see that the CLI has been installed but there was some permission issue in node-pre-gyp.
Just to be safe, you should install the ghost-cli with a user with sudo (admin) privileges, just like the docs say. Those errors are most definitely due to not installing it with sudo.
One thing to note here is that there shouldn’t be any errors during the ghost-cli installation in order for the whole process to function correctly. And assuming you’ve followed everything in the docs I believe there shouldn’t be anything else to worry about, if the cli is installed correctly.
I am installing with the root user. Also the docs talk about errors during installing of a ghost instance. Since my ghost instance is already installed and was working fine before, so I don’t really know what to do.
These kind of problems may arise when using root. That’s why the docs emphasize in using a non-root user by showing steps to create it.
I’m not sure how you got it working with root, but be aware that trying to make it work this way is a security issue. Not so long ago I tried doing things only with root and these kind of problems were a day to day thing. I’m not sure what else to recommend you, but I’m pretty sure this is no longer a problem with NVM.
Yup, When I initially started out, everything was just for the fun of it so everything was been done with the root user but I have moved to a different user over time and locked out the root one. The blog was the only thing running on root, I am currently trying to change the permission of the ghost folder to my other user and see if it works
I think I got it. I saw this issue which made me realise this error that I am getting is due to the service not being able to start. I have set up correct folder and file permissions but still its failing. So, I looked up the service file in ghost/system/files and the content is thus
[Unit]
Description=Ghost systemd service for blog: blogname
Documentation=https://docs.ghost.org
[Service]
Type=simple
WorkingDirectory=/var/www/folder/ghost
User=998
Environment="NODE_ENV=production"
ExecStart=/usr/bin/node /usr/bin/ghost run
Restart=always
[Install]
WantedBy=multi-user.target
As you can see the ExecStart is all wrong! Maybe some other things are all wrong in the service file too. It would be great if you can help me fix this file. I think that would fix my issues!
I have replaced /usr/bin/node with the node location in my nvm. But it is still failing. The things that can matter are the User key (no idea what it does) and /usr/bin/ghost was initially a link to the old node_modules folder. I deleted it and created a symlink to the nvm node modules folder.
I had to stop the errored systemd process and after that the yargs error went away, replaced by an error which set my user and systemd was not setup (which was) so, I redid the setup command and it WORKS!!
Thanks a lot for your help and putting me in the correct direction. Have a great day!
Glad it worked! Sorry I couldn’t respond to the other comments. For anyone who’s having a similar problem. Just make sure you have the correct path to node and take a light read on the ghost cli commands, it might save you a lot of trouble.