Installing ghost-cli using Yarn does not work

I cannot install ghost-cli using the Yarn package manager.

The docs state I can use Yarn to install ghost-cli. It doesn’t give the command, so I assume I can do the following but I get an error:

yarn set version 4.5.3
yarn add ghost-cli@latest -g

Unknown Syntax Error: Command not found; did you mean one of:

  0. yarn add [--json] [-F,--fixed] [-E,--exact] [-T,--tilde] [-C,--caret] [-D,--dev] [-P,--peer] [-O,--optional] [--prefer-dev] [-i,--interactive] [--cached] [--mode #0] ...
  1. yarn add [--json] [-F,--fixed] [-E,--exact] [-T,--tilde] [-C,--caret] [-D,--dev] [-P,--peer] [-O,--optional] [--prefer-dev] [-i,--interactive] [--cached] [--mode #0] ...

I try without the -g. It installs, but the ghost command is not found:

$ yarn add ghost-cli@latest
➤ YN0000: · Yarn 4.5.3
➤ YN0000: ┌ Resolution step
➤ YN0085: │ + ghost-cli@npm:1.26.1, @samverschueren/stream-to-observable@npm:0.3.1, @sindresorhus/is@npm:0.14.0, @sindresorhus/is@npm:0.7.0, @sindresorhus/is@npm:4.6.0, and 533 more.
➤ YN0000: └ Completed in 9s 637ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 0s 249ms
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0007: │ yarn@npm:1.22.19 must be built because it never has been before or the last one failed
➤ YN0000: └ Completed in 0s 922ms
➤ YN0000: · Done with warnings in 10s 883ms

$ ghost help
Command 'ghost' not found, did you mean:
  command 'gost' from snap gost (2.12.0)
  command 'host' from deb bind9-host (1:9.18.28-0ubuntu0.22.04.1)
  command 'gfhost' from deb gfarm-client (2.7.17+dfsg-1build2)
  command 'rhost' from deb jdresolve (0.6.1-5.1)
  command 'xhost' from deb x11-xserver-utils (7.7+9build1)
  command 'qhost' from deb gridengine-client (8.1.9+dfsg-10build1)
  command 'khost' from deb knot-host (3.1.6-1ubuntu1)
  command 'gost' from deb gost (0.1.0+git20181204.5afeda5e-1.1ubuntu0.22.04.2)
See 'snap info <snapname>' for additional versions.

I learn that Yarn does not allow globally installed packages now and instead encourage the use of temporary package execution using the yarn dlx sub-command. I run ‘ghost install local’ from the ‘ghost-cli’ package and I get an error saying a dependency has no candidates:

$ yarn dlx ghost install local -p ghost-cli@latest
➤ YN0000: · Yarn 4.5.3
➤ YN0000: ┌ Resolution step
➤ YN0082: │ @tryghost/email-content-generator@npm:0.0.0: No candidates found
➤ YN0000: └ Completed in 10s 330ms
➤ YN0000: · Failed with errors in 10s 351ms

Ghost Version

5.104.2

Node.js Version

20.18.1

How did you install Ghost?

I’m trying to install Ghost using the ghost-cli on Ubuntu 22.04

Database type

SQLite3

Browser & OS version

Ubuntu 22.04

the instructions say you can use yarn, but then shows you how to install it with npm. you might want to try that instead of yarn

npm install ghost-cli@latest -g

if you prefer using yarn the command is
yarn global add [package]

Thank you for your reply @NickAbs. Unfortunately the ‘yarn global’ commands were removed in yarn 2.x which was a long time ago. The ‘yarn dlx’ command that I used in the original post has superseded it.

I solved it (I’m using yarn 4.5.3):

# Install ghost-cli as usual
yarn add ghost-cli@latest
# Use yarn to execute the binary
yarn exec ghost install local

Explanation
When the Ghost docs say to install with npm install ghost-cli@latest -g, the ghost command only works afterwards because the the -g is installing the package globally, and is executable because your node installation has modified your PATH variable so the binaries that come with packages are in a location known by your shell, allowing you to just type ghost directly and your shell knows where the ghost binary is. When you output the contents of PATH you’ll see a path to a bin directory within node:

echo $PATH
/home/<user>/.nvm/versions/node/v20.18.1/bin:(...other directories in PATH...)

So when you run yarn add ghost-cli@latest, the ghost-cli package installs everything fine (as you can see in the second code block of my original post), but you can’t run ghost directly in your shell because yarn installs packages in a place that isn’t in your PATH variable. You can check where the ghost binary is by running:

yarn bin ghost
# outputs something like
/home/<user>/.yarn/berry/cache/ghost-cli-npm-1.26.1-84cc464b9d-10c0.zip/node_modules/ghost-cli/bin/ghost

Yarn does know where the ghost binary is though, so to install Ghost using ghost-cli, you run yarn exec ghost install local.

1 Like

apologies, I should have checked (it seems the old version of yarn is still the default on Mac and ubuntu). Glad you sorted it out.

I should note that at time of writing, using yarn 4.x still fails because the process tries to run yarn install --no-emoji which is now an invalid flag, however I have submitted an issue to get yarn 4.x supported considering that it’s stable now. Using yarn 1.x works though. To use it, run yarn set version 1.22.22 in your project directory.