22

I use mac and I installed gatsby-cli by:

npm install --global gatsby-cli

and 'npm root -g' command prints:

/usr/local/lib/node_modules/npm/lib/node_modules

npm successfully installed gatsby but, I cannot run gatsby command (gatsby --version, gatsby --help) Whenever I type and run "gatsby --version" it prints:

-bash: gatsby: command not found

Is there any way I can fix this problem??

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
leonkong
  • 459
  • 3
  • 5
  • 15

4 Answers4

43

you have to update your config. You may have to follow few steps

Set Config

remove existing config

npm config delete prefix 

set new config

npm config set prefix /usr/local

Install gatsby

npm i -g gatsby-cli

now check version

gatsby --version
Amruth
  • 5,792
  • 2
  • 28
  • 41
5

Instead of trying to install globally, you can use npx

 npx gatsby new my_dir_name

Then run:

npx gatsby develop

Then:

npx gatsby build

And then you can run them using

npm run develop
npm run build
Dharman
  • 30,962
  • 25
  • 85
  • 135
Silikhe
  • 69
  • 1
  • 3
2

I came across the same issue. npx gatsby -v worked. Hope this helps somebody. Reference: https://github.com/gatsbyjs/gatsby/issues/15276#issuecomment-507340096

mnishiguchi
  • 2,051
  • 23
  • 17
  • This doesn't actually mean it is installed locally. "npx" will just pull from the NPM global repository to grab it temporarily and then run the command with it, but it isn't installed locally which means anytime you want to do anything with gatsby you have to start it with "npx". https://github.com/npm/npx – BlueCaret Jan 07 '21 at 15:12
2

In my case i was missing sudo on install:

sudo npm i -g gatsby-cli

Cristian Muscalu
  • 9,007
  • 12
  • 44
  • 76