How to use gatsby-cli from local node_modules.
Usually, Gatsby client is installed globally (note the -g parameter).
npm install -g gatsby-cli
But how to use a different version if needed for one project? For example version “5.7.0”.
If it’s not yet installed, install it without -g parameter, so it would not interfere with the globally installed version. It will be installed locally in node_modules.
npm install gatsby-cli@5.7.0
It will install Gatsby client into ./node_modules/gatsby-cli/cli.js . To use it we just have to run it with node.
To test it out we can check the version number of local and global gatsby-cli.
Local:
node ./node_modules/gatsby-cli/cli.js --version
Global:
gatsby --version
They should produce different results if they are at different versions.