gatsby --version > -bash: gatsby: command not found
Asked Answered
P

4

24

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??

Preponderate answered 18/9, 2018 at 4:11 Comment(9)
could you please try gatsby info instead of checking version ?Phraseology
gatsby info >>>> -bash: gatsby: command not foundPreponderate
have you reopened the terminal ?Phraseology
I use bash terminal. I don't understand what you are meaning by "responded the terminal"Preponderate
i mean close your bash terminal and open terminal then run the command and checkPhraseology
I closed and opened again.. it returns the same message.. -bash: gatsby: command not foundPreponderate
check my updated ansPhraseology
Thankyou! it solved~ Now i can run gatsby --versionPreponderate
Take a look at this post for a few different approaches to installing gatsby-cli.Brunswick
P
46

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
Phraseology answered 18/9, 2018 at 4:34 Comment(5)
I did it.. but it still returns >>>-bash: gatsby: command not foundPreponderate
oh! it helps!! now i can get result for gatsby --version Thankyou a lot!!!Preponderate
Nice. Can you elaborate what the issue is? Why does the solution work?Disgraceful
@XaverFleer npm config prefix might be pointing to incorrect location. so we are removing it and setting new location.Phraseology
Great. It worked on my end, now set at 3.0 (I had installed gatsby locally before in the project folder) Gatsby CLI version: 3.0.0 Gatsby version: 3.0.0Sent
K
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
Ker answered 31/3, 2021 at 23:16 Comment(2)
this seems like the cleanest solution IMOMicrobicide
This solution worked for me. For some unknown reason, I could not run then npm global command. You save my day. thank you.Moguel
O
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

Optometer answered 10/1, 2020 at 23:33 Comment(1)
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". github.com/npm/npxVic
V
2

In my case i was missing sudo on install:

sudo npm i -g gatsby-cli

Vicinage answered 20/2, 2022 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.