Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gatsby --version > -bash: gatsby: command not found

Tags:

npm

gatsby

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

like image 989
leonkong Avatar asked Sep 18 '18 04:09

leonkong


People also ask

What is Gatsby npm?

Gatsby is a free and open source framework based on React that helps developers build blazing fast websites and apps. It combines the control and scalability of dynamically rendered sites with the speed of static-site generation, creating a whole new web of possibilities.


4 Answers

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
like image 141
Amruth Avatar answered Oct 17 '22 00:10

Amruth


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

like image 41
mnishiguchi Avatar answered Oct 17 '22 00:10

mnishiguchi


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
like image 44
Silikhe Avatar answered Oct 16 '22 22:10

Silikhe


In my case i was missing sudo on install:

sudo npm i -g gatsby-cli

like image 30
Cristian Muscalu Avatar answered Oct 16 '22 22:10

Cristian Muscalu