Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatsby: command not found after npm install #15276

Closed
marieqg opened this issue Jul 1, 2019 · 7 comments
Closed

gatsby: command not found after npm install #15276

marieqg opened this issue Jul 1, 2019 · 7 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@marieqg
Copy link

marieqg commented Jul 1, 2019

When I try to install gatsby running npm install 'gatsby-cli -g' , it does not work : when I run 'gatsby --help', it shows:
'bash:gatsby command not found'

I have tried:

  1. uninstalling and reinstalling NPM
  2. this gitHub solution : "Gatsby: command not found" on trying to run Gatsby command after installing npm install --global gatsby-cli #4967
    I get a permission error when trying to change npm config set prefix /usr/local
  3. Uninstalling and reinstally Gatsby

I'm working on mac (version 10.14.5).
My environment details are as follows:
npm -v : 6.9.0
node -v : v10.16.0

As for permission, I already have an "export PATH=~/.npm-global/bin:$PATH" in a .bash_profile that is in my ~/.npm-global folder (https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally).

What can I do to make it work?

Thanks in advance,
Marie

@pieh
Copy link
Contributor

pieh commented Jul 1, 2019

It does seem like globally installed packages for some reason not work in your environment :/

Here's another article worth to go through: https://medium.com/@jagatjyoti.1si13cs040/npm-g-install-npm-package-not-working-as-desired-why-why-why-19795abf0b59

If this won't help, there is workaround this that you can try - instead of trying to install and use globally installed gatsby-cli, you can use npx:

npx gatsby new <directory_name>
npx gatsby develop
npx gatsby build

etc. or add commands to scripts in package.json:

"scripts": {
  "develop": "gatsby develop",
  "build": "gatsby build"
}

and run them with

npm run develop
npm run build

@pieh pieh added the type: question or discussion Issue discussing or asking a question about Gatsby label Jul 1, 2019
@marieqg
Copy link
Author

marieqg commented Jul 2, 2019

Thank's a lot! I solved my problem :) It was a global installation problem indeed!
I followed the github solution ( #4967) but did a "sudo npm install gatsby-cli -g –"

@marieqg marieqg closed this as completed Jul 2, 2019
@Olanetsoft
Copy link
Contributor

Oh my God ! It worked ...... Thanks @pieh

@ray760
Copy link

ray760 commented Jan 2, 2020

I know this is an older post, but being that it showed up first in my search I figured I'd share my solution.

My global packages on my Windows10 (Work machine, I'd much rather a Mac) are set to install at the below path.

/c/Users/{username}/AppData/Roaming/npm

So I added this to my PATH variable and now it finds the installation. You can search for "Environment Variables", click Path and add the path there, or if you're like me and don't have admin rights you can add via Git Bash in Windows like below.

PATH=$PATH:/c/Users/{username}/AppData/Roaming/npm

You can also create an Bash alias and have it automatically run when you start Git Bash.

@ecanas44
Copy link

ecanas44 commented Mar 9, 2020

This is what worked for me pretty easily:
firebase/firebase-tools#113 (comment)

@Hasnainzxc
Copy link

worked for me i was trying in gatsby new

@SSylvain1989
Copy link

Hello , this command work like a charm for me 👍

i'm on w10 with ubuntu terminal on windows terminal
❯ node -v
v10.23.0
❯ npm -v
6.14.8

" sudo npm install gatsby-cli -g" resolve my problem " "Gatsby: command not found" on trying to run Gatsby command after installing npm install --global gatsby-cli" 👍

for the information , still have this :
❯ npm -g ls --depth=0
/usr/local/lib
└── (empty)

but "gatsby new test-gatsby" work for me
and after run just warnings like below

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

however still working how to resolve this

" npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated highlight.js@8.9.1: Version no longer supported. Upgrade to @latest
npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
/usr/bin/gatsby -> /usr/lib/node_modules/gatsby-cli/cli.js

core-js@2.6.12 postinstall /usr/lib/node_modules/gatsby-cli/node_modules/core-js
node -e "try{require('./postinstall')}catch(e){}""

after install gatsby

❯ gatsby --version
Gatsby CLI version: 2.15.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

No branches or pull requests

7 participants