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" on trying to run Gatsby command after installing npm install --global gatsby-cli #4967

Closed
pereiraryan opened this issue Apr 13, 2018 · 46 comments
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@pereiraryan
Copy link

pereiraryan commented Apr 13, 2018

On referring to the docs on gatsby page, Was not able to run the gatsby command for the new static site.

My environment details are as follows:
npm -v : 3.10.10
node -v : v6.14.1.
Operating System: Linux 4.4.0-119-generic (ubuntu 16.04)
These are the file structure on installing gastby cli

-- gatsby-cli@1.1.50 
  +-- core-js@2.5.5 
  +-- update-notifier@2.4.0 
  | +-- configstore@3.1.2 
  | +-- is-ci@1.1.0
  | | `-- ci-info@1.1.3 
  | `-- latest-version@3.1.0
  |   `-- package-json@4.0.1
  |     +-- got@6.7.1
  |     | `-- lowercase-keys@1.0.1 
  |     `-- registry-auth-token@3.3.2
  |       `-- rc@1.2.6 
  `-- yurnalist@0.2.1
    +-- inquirer@3.3.0
    | +-- ansi-escapes@3.1.0 
    | `-- external-editor@2.2.0 
    |   `-- iconv-lite@0.4.21 
    |     `-- safer-buffer@2.1.2 
    `-- invariant@2.2.4 

On entering the new create command : gatsby new gatsby-site
i get an error saying :gatsby: command not found

What am i doing wrong here.

@m-allanson
Copy link
Contributor

m-allanson commented Apr 14, 2018

Does npm -g ls --depth=0 list gatsby-cli as being installed?

@m-allanson m-allanson added the type: question or discussion Issue discussing or asking a question about Gatsby label Apr 14, 2018
@pereiraryan
Copy link
Author

Yes it shows: gatsby-cli@1.1.50

@pereiraryan
Copy link
Author

is it like gatsby is not supported on linux ?

@KyleAMathews
Copy link
Contributor

Lots of people use gatsby on Linux. Check if other npm global binaries work there.

@pereiraryan
Copy link
Author

other npm binaries work fine.

@KyleAMathews
Copy link
Contributor

Not sure. Perhaps try uninstalling and then reinstalling gatsby-cli. Regardless, this is an npm install problem it sounds like not anything with gatsby. Lots of people are using gatsby on Linux and we regularly test on linux. If you do discover something specific that's causing trouble with your environment, please open a new issue and we'll try to fix it.

@pereiraryan
Copy link
Author

i tried cloning the main repo and ran npm install which gave me a npm warning : npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

@KyleAMathews
Copy link
Contributor

fsevents is a Mac dependency so the message is saying npm won't install it.

@pereiraryan
Copy link
Author

After some trial & error, I finally found the solution. You have to change the “npm config prefix” like so: npm config set prefix /usr/local
previously It appeared that it installed “gatsby-cli” in my local folder that is /Users/YOURUSERNAME/node_modules and not in the global NPM folder.

and then when I re-ran npm root -g, I got the correct root folder: /usr/local/lib/node_modules
👍

@nicfournier
Copy link

@pereiraryan Gotcha!

@bfeldman89
Copy link

@pereiraryan can you advise what you did more step-by-step? I am having the same issue.

@FrancesCoronel
Copy link

FrancesCoronel commented Sep 9, 2018

@bfeldman89 Here are the steps I took that resolved the issue for me as well based on @pereiraryan's steps.

Step 1 - Set Config

If you are using nvm, you want to use

npm config delete prefix

since nvm is not compatible with the npm config "prefix" option.

Otherwise, if you don't use nvm, you can just run

npm config set prefix /usr/local

Step 2 - Install Gatsby

Install gatsby globally with npm

npm i -g gatsby-cli

Step 3 - Verify Installation

Verify gatsby is installed correctly by listing all the packages you have installed globally at the first level (so not dependencies)

npm -g ls --depth=0

which should output something like this

/usr/local/lib
└── gatsby-cli@1.1.58

Step 4 - Huzzah

Success! Now you can use gatsby in all its loveliness.

gatsby new lovely-gatsby-site

@tfuqua
Copy link

tfuqua commented Sep 25, 2018

This fixed issue for me

@F-DK
Copy link

F-DK commented Oct 14, 2018

Thanks @pereiraryan and @fvcproductions, solved it for me as well.

@mcstean
Copy link

mcstean commented Oct 18, 2018

after typing: npm i -g gatsby-cli I receive an error message and i don't know what to do.
screenshot from 2018-10-18 19-30-03

@DSchau
Copy link
Contributor

DSchau commented Oct 18, 2018

@mcstean sudo chmod 755 /usr/local/lib perhaps?

@mininaim
Copy link

mininaim commented Nov 1, 2018

This issue in creating a new gatsby site is still appearing, I reinstalled gatsby-cli as global again and over again ...

`gatsby new lovely-gatsby-site
info Creating new site from git: https://github.com/gatsbyjs/gatsby-starter-default.git
Clonage dans 'lovely-gatsby-site'...
remote: Enumerating objects: 969, done.
remote: Total 969 (delta 0), reused 0 (delta 0), pack-reused 969
Réception d'objets: 100% (969/969), 1.25 MiB | 314.00 KiB/s, fait.
Résolution des deltas: 100% (552/552), fait.
success Created starter directory layout
info Installing packages...
yarn install v1.9.4
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍 Resolving packages...
warning gatsby > eslint > file-entry-cache > flat-cache > circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
warning gatsby-plugin-sharp > imagemin-mozjpeg > mozjpeg > bin-build > download > gulp-decompress > gulp-util@3.0.8: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
warning gatsby-plugin-sharp > imagemin-pngquant > pngquant-bin > bin-wrapper > bin-version-check > bin-version > execa > cross-spawn-async@2.2.5: cross-spawn no longer requires a build toolchain, use it instead
[2/4] 🚚 Fetching packages...
[3/4] 🔗 Linking dependencies...
[4/4] 📃 Building fresh packages...
[-/5] ⠠ waiting...
[2/5] ⠠ sharp
[-/5] ⠠ waiting...
[-/5] ⠠ waiting...
error /Applications/MAMP/htdocs/lovely-gatsby-site/node_modules/sharp: Command failed.
Exit code: 1
Command: (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
Arguments:
Directory: /Applications/MAMP/htdocs/lovely-gatsby-site/node_modules/sharp
Output:
info sharp Detected globally-installed libvips v8.7.0
info sharp Building from source via node-gyp
gyp info it worked if it ends with ok
gyp info using node-gyp@3.7.0
gyp info using node@10.8.0 | darwin | x64
gyp info spawn /usr/local/bin/python2
gyp info spawn args [ '/usr/local/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/Applications/MAMP/htdocs/lovely-gatsby-site/node_modules/sharp/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/usr/local/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/MiniNaim/.node-gyp/10.8.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/Users/MiniNaim/.node-gyp/10.8.0',
gyp info spawn args '-Dnode_gyp_dir=/usr/local/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/Users/MiniNaim/.node-gyp/10.8.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/Applications/MAMP/htdocs/lovely-gatsby-site/node_modules/sharp',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.' ]
No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12)
gyp ERR! System Darwin 18.0.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Applications/MAMP/htdocs/lovely-gatsby-site/node_modules/sharp
gyp ERR! node -v v10.8.0

error Command failed: yarnpkg

Error: Command failed: yarnpkg

  • index.js:236 Promise.all.then.arr
    [lib]/[gatsby-cli]/[execa]/index.js:236:11

  • util.js:16 tryCatcher
    [lib]/[gatsby-cli]/[bluebird]/js/release/util.js:16:23

  • promise.js:512 Promise._settlePromiseFromHandler
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:512:31

  • promise.js:569 Promise._settlePromise
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:569:18

  • promise.js:614 Promise._settlePromise0
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:614:10

  • promise.js:694 Promise._settlePromises
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:694:18

  • promise.js:638 Promise._fulfill
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:638:18

  • promise_array.js:126 PromiseArray._resolve
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise_array.js:126:19

  • promise_array.js:144 PromiseArray._promiseFulfilled
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise_array.js:144:14

  • promise.js:574 Promise._settlePromise
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:574:26

  • promise.js:614 Promise._settlePromise0
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:614:10

  • promise.js:694 Promise._settlePromises
    [lib]/[gatsby-cli]/[bluebird]/js/release/promise.js:694:18

  • async.js:138 _drainQueueStep
    [lib]/[gatsby-cli]/[bluebird]/js/release/async.js:138:12

  • async.js:131 _drainQueue
    [lib]/[gatsby-cli]/[bluebird]/js/release/async.js:131:9

  • async.js:147 Async._drainQueues
    [lib]/[gatsby-cli]/[bluebird]/js/release/async.js:147:5

  • async.js:17 Immediate.Async.drainQueues [as _onImmediate]
    [lib]/[gatsby-cli]/[bluebird]/js/release/async.js:17:14
    `

@mcstean
Copy link

mcstean commented Nov 9, 2018

@DSchau please scan you advise on a book or basic stuffs beginners should master to easily find their way ?
Thanks

@DSchau
Copy link
Contributor

DSchau commented Nov 9, 2018

@mcstean what exactly are you looking for? Specifically in re: to Gatsby, or more unix-like stuff?

@mcstean
Copy link

mcstean commented Nov 10, 2018

@DSchau More Unix like as I admit also Being a fan.
Is true I really wish to understand how things work to ease the deployment of existing open source application to small businesses.

@TS22082
Copy link

TS22082 commented Nov 22, 2018

Oh god, how do I set it back to what it was. I Followed @fvcproductions instructions and the errors i'm getting no matter what I run or in what project i'm in are:

`
Error: EPERM: operation not permitted, mkdir 'C:\Program Files\Git\usr\local'
TypeError: Cannot read property 'get' of undefined
at errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:205:18)
at C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js:78:20
at cb (C:\Program Files\nodejs\node_modules\npm\lib\npm.js:228:22)
at C:\Program Files\nodejs\node_modules\npm\lib\npm.js:266:24
at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:83:7
at Array.forEach ()
at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:82:13
at f (C:\Program Files\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
at afterExtras (C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:173:20)
at C:\Program Files\nodejs\node_modules\npm\node_modules\mkdirp\index.js:47:53
C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:205
if (npm.config.get('json')) {
^

TypeError: Cannot read property 'get' of undefined
at process.errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:205:18)
at emitOne (events.js:116:13)
at process.emit (events.js:211:7)
at process._fatalException (bootstrap_node.js:391:26)
Error: EPERM: operation not permitted, mkdir 'C:\Program Files\Git\usr\local'
TypeError: Cannot read property 'get' of undefined
at errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:205:18)
at C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js:78:20
at cb (C:\Program Files\nodejs\node_modules\npm\lib\npm.js:228:22)
at C:\Program Files\nodejs\node_modules\npm\lib\npm.js:266:24
at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:83:7
at Array.forEach ()
at C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:82:13
at f (C:\Program Files\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
at afterExtras (C:\Program Files\nodejs\node_modules\npm\lib\config\core.js:173:20)
at C:\Program Files\nodejs\node_modules\npm\node_modules\mkdirp\index.js:47:53
C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:205
if (npm.config.get('json')) {
^

TypeError: Cannot read property 'get' of undefined
at process.errorHandler (C:\Program Files\nodejs\node_modules\npm\lib\utils\error-handler.js:205:18)
at emitOne (events.js:116:13)
at process.emit (events.js:211:7)
at process._fatalException (bootstrap_node.js:391:26)
`

So even my projects that were working using the normal "create-react-app" dont work.

@mergederg
Copy link

mergederg commented Dec 7, 2018

I'm seeing this as well ("command not found: gatsby" upon running gatsby --version after npm install --global gatsby. My other globally installed binaries (grunt and node-reveal) work for me as expected.

OS X here, with npm 6.4.1 and 11.3.0. Node is installed via homebrew, so my value for prefix is /usr/local/Cellar/node/11.3.0_1

@CLantigua2
Copy link

@bfeldman89 Here are the steps I took that resolved the issue for me as well based on @pereiraryan's steps.

Step 1 - Set Config

If you are using nvm, you want to use

npm config delete prefix

since nvm is not compatible with the npm config "prefix" option.

Otherwise, if you don't use nvm, you can just run

npm config set prefix /usr/local

Step 2 - Install Gatsby

Install gatsby globally with npm

npm i -g gatsby-cli

Step 3 - Verify Installation

Verify gatsby is installed correctly by listing all the packages you have installed globally at the first level (so not dependencies)

npm -g ls --depth=0

which should output something like this

/usr/local/lib
└── gatsby-cli@1.1.58

Step 4 - Huzzah

Success! Now you can use gatsby in all its loveliness.

gatsby new lovely-gatsby-site

This worked great for me but I had to manually go into the npmrc file because my path has a space between the file. So if anybody else has the issue where their npm breaks because of this, try the following.

  1. Locate your .npmrc file and open it (I just used notepad)
  2. look at your current prefix location. (For me it was prefix=C:/Program Files/Git/usr/local)
  3. If you're looks something like mine with the space between the path folder add the / between the files like you would in git.
    ex. prefix=C:/Program/Files/Git/usr/local

@stephangriesel
Copy link

Moved to new machine recently, just installing Gatsby CLI globally should fix this.

@PradeepLinkites
Copy link

On referring to the docs on gatsby page, Was not able to run the gatsby command for the new static site.

My environment details are as follows:
npm -v : 3.10.10
node -v : v6.14.1.
Operating System: Linux 4.4.0-119-generic (ubuntu 16.04)
These are the file structure on installing gastby cli

-- gatsby-cli@1.1.50 
  +-- core-js@2.5.5 
  +-- update-notifier@2.4.0 
  | +-- configstore@3.1.2 
  | +-- is-ci@1.1.0
  | | `-- ci-info@1.1.3 
  | `-- latest-version@3.1.0
  |   `-- package-json@4.0.1
  |     +-- got@6.7.1
  |     | `-- lowercase-keys@1.0.1 
  |     `-- registry-auth-token@3.3.2
  |       `-- rc@1.2.6 
  `-- yurnalist@0.2.1
    +-- inquirer@3.3.0
    | +-- ansi-escapes@3.1.0 
    | `-- external-editor@2.2.0 
    |   `-- iconv-lite@0.4.21 
    |     `-- safer-buffer@2.1.2 
    `-- invariant@2.2.4 

On entering the new create command : gatsby new gatsby-site
i get an error saying :gatsby: command not found

What am i doing wrong here.

On referring to the docs on gatsby page, Was not able to run the gatsby command for the new static site.

My environment details are as follows:
npm -v : 3.10.10
node -v : v6.14.1.
Operating System: Linux 4.4.0-119-generic (ubuntu 16.04)
These are the file structure on installing gastby cli

-- gatsby-cli@1.1.50 
  +-- core-js@2.5.5 
  +-- update-notifier@2.4.0 
  | +-- configstore@3.1.2 
  | +-- is-ci@1.1.0
  | | `-- ci-info@1.1.3 
  | `-- latest-version@3.1.0
  |   `-- package-json@4.0.1
  |     +-- got@6.7.1
  |     | `-- lowercase-keys@1.0.1 
  |     `-- registry-auth-token@3.3.2
  |       `-- rc@1.2.6 
  `-- yurnalist@0.2.1
    +-- inquirer@3.3.0
    | +-- ansi-escapes@3.1.0 
    | `-- external-editor@2.2.0 
    |   `-- iconv-lite@0.4.21 
    |     `-- safer-buffer@2.1.2 
    `-- invariant@2.2.4 

On entering the new create command : gatsby new gatsby-site
i get an error saying :gatsby: command not found

What am i doing wrong here.

I was also getting same error but my issue has resolved by using cammand with sudo

@marieqg
Copy link

marieqg commented Jun 30, 2019

@bfeldman89 Here are the steps I took that resolved the issue for me as well based on @pereiraryan's steps.

Step 1 - Set Config

If you are using nvm, you want to use

npm config delete prefix

since nvm is not compatible with the npm config "prefix" option.

Otherwise, if you don't use nvm, you can just run

npm config set prefix /usr/local

Step 2 - Install Gatsby

Install gatsby globally with npm

npm i -g gatsby-cli

Step 3 - Verify Installation

Verify gatsby is installed correctly by listing all the packages you have installed globally at the first level (so not dependencies)

npm -g ls --depth=0

which should output something like this

/usr/local/lib
└── gatsby-cli@1.1.58

Step 4 - Huzzah

Success! Now you can use gatsby in all its loveliness.

gatsby new lovely-gatsby-site

Hello,
I'm having the same issue.

When I run gatsby --version, I get a : -bash: gatsby: command not found.
In the step 3, when I run( npm -g ls --depth=0), I get this result :

/Users/mariequittelier/npm/lib
└── gatsby-cli@2.7.7

My environment details are as follows:
npm -v : 6.9.0
node -v : v10.16.0

What can I do to make it work?

Thanks in advance,
Marie

@NoftScarlet
Copy link

after typing: npm i -g gatsby-cli I receive an error message and i don't know what to do.
screenshot from 2018-10-18 19-30-03

sudo chmod 755 /usr/local/lib
then
sudo npm i -g gatsby-cli
did the trick for me. Not sure if the chmod is required.

@rutikwankhade
Copy link

till step 3 it worked for me but but, after that when I write command gatsby new my-blog ,it says gatsby is not recognized as internal or external command.
Suggest anything I can check ,verify so that it will work.

@rutikwankhade
Copy link

rutikwankhade commented Nov 14, 2019

I'm seeing this as well ("command not found: gatsby" upon running gatsby --version after npm install --global gatsby. My other globally installed binaries (grunt and node-reveal) work for me as expected.

OS X here, with npm 6.4.1 and 11.3.0. Node is installed via homebrew, so my value for prefix is /usr/local/Cellar/node/11.3.0_1

I am having the same problem. I have Windows 10 OS , the prefix is prefix=/usr/local after running command 'gatsby --version' it says ''gatsby' cannot be recognized as internal or external command. I installed gatsby cli successfully and when I run command -g ls --depth=0 it shows +-- gatsby-cli@2.8.10
`-- npm@6.13.0

what to do now ?
Screenshot (215)

@ishan501
Copy link

I'm seeing this as well ("command not found: gatsby" upon running gatsby --version after npm install --global gatsby. My other globally installed binaries (grunt and node-reveal) work for me as expected.
OS X here, with npm 6.4.1 and 11.3.0. Node is installed via homebrew, so my value for prefix is /usr/local/Cellar/node/11.3.0_1

I am having the same problem. I have Windows 10 OS , the prefix is prefix=/usr/local after running command 'gatsby --version' it says ''gatsby' cannot be recognized as internal or external command. I installed gatsby cli successfully and when I run command -g ls --depth=0 it shows +-- gatsby-cli@2.8.10
`-- npm@6.13.0

what to do now ?
Screenshot (215)

I'm having the same issue! It's showing all good but when I run the command it says 'command not found'. Can anyone help?

@rutikwankhade
Copy link

I'm seeing this as well ("command not found: gatsby" upon running gatsby --version after npm install --global gatsby. My other globally installed binaries (grunt and node-reveal) work for me as expected.
OS X here, with npm 6.4.1 and 11.3.0. Node is installed via homebrew, so my value for prefix is /usr/local/Cellar/node/11.3.0_1

I am having the same problem. I have Windows 10 OS , the prefix is prefix=/usr/local after running command 'gatsby --version' it says ''gatsby' cannot be recognized as internal or external command. I installed gatsby cli successfully and when I run command -g ls --depth=0 it shows +-- gatsby-cli@2.8.10
`-- npm@6.13.0
what to do now ?
Screenshot (215)

I'm having the same issue! It's showing all good but when I run the command it says 'command not found'. Can anyone help?

ok. lets try this. Go to your system environment variables and add environment variable as my-admin-account with value C:\Users\AppData\Roaming\npm.
this might work.
check this, it might help.
#2509 (comment)

@ishan501
Copy link

I'm seeing this as well ("command not found: gatsby" upon running gatsby --version after npm install --global gatsby. My other globally installed binaries (grunt and node-reveal) work for me as expected.
OS X here, with npm 6.4.1 and 11.3.0. Node is installed via homebrew, so my value for prefix is /usr/local/Cellar/node/11.3.0_1

I am having the same problem. I have Windows 10 OS , the prefix is prefix=/usr/local after running command 'gatsby --version' it says ''gatsby' cannot be recognized as internal or external command. I installed gatsby cli successfully and when I run command -g ls --depth=0 it shows +-- gatsby-cli@2.8.10
`-- npm@6.13.0
what to do now ?
Screenshot (215)

I'm having the same issue! It's showing all good but when I run the command it says 'command not found'. Can anyone help?

ok. lets try this. Go to your system environment variables and add environment variable as my-admin-account with value C:\Users\AppData\Roaming\npm.
this might work.
check this, it might help.
#2509 (comment)

I've already set that value. npm -g ls --depth=0 returns

C:\usr\local

Any other things to debug?

@ishan501
Copy link

Finally fixed this. Gatsby installed at some other folder so adding the path to the environment variable solved the issue. Thanks! @rutikwankhade

@kinucris
Copy link

kinucris commented Apr 6, 2020

@bfeldman89 Here are the steps I took that resolved the issue for me as well based on @pereiraryan's steps.

Step 1 - Set Config

If you are using nvm, you want to use

npm config delete prefix

since nvm is not compatible with the npm config "prefix" option.

Otherwise, if you don't use nvm, you can just run

npm config set prefix /usr/local

Step 2 - Install Gatsby

Install gatsby globally with npm

npm i -g gatsby-cli

Step 3 - Verify Installation

Verify gatsby is installed correctly by listing all the packages you have installed globally at the first level (so not dependencies)

npm -g ls --depth=0

which should output something like this

/usr/local/lib
└── gatsby-cli@1.1.58

Step 4 - Huzzah

Success! Now you can use gatsby in all its loveliness.

gatsby new lovely-gatsby-site

Thanks!
Work for me!

@Kamez
Copy link

Kamez commented May 3, 2020

I got this error

`/usr/local/lib/node_modules/gatsby-cli/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
throw ex;
^

Error: Package exports for '/usr/local/lib/node_modules/gatsby-cli/node_modules/clipboardy' do not define a '.' subpath
at resolveExports (internal/modules/cjs/loader.js:419:17)
at Function.Module._findPath (internal/modules/cjs/loader.js:492:20)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:787:27)
at Function.Module._load (internal/modules/cjs/loader.js:693:27)
at Module.require (internal/modules/cjs/loader.js:864:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object. (/usr/local/lib/node_modules/gatsby-cli/lib/create-cli.js:24:20)
at Module._compile (internal/modules/cjs/loader.js:971:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
at Module.load (internal/modules/cjs/loader.js:822:32) {
code: 'MODULE_NOT_FOUND'
}`

please help me.

@Tokhirjon
Copy link

@bfeldman89 Here are the steps I took that resolved the issue for me as well based on @pereiraryan's steps.

Step 1 - Set Config

If you are using nvm, you want to use

npm config delete prefix

since nvm is not compatible with the npm config "prefix" option.

Otherwise, if you don't use nvm, you can just run

npm config set prefix /usr/local

Step 2 - Install Gatsby

Install gatsby globally with npm

npm i -g gatsby-cli

Step 3 - Verify Installation

Verify gatsby is installed correctly by listing all the packages you have installed globally at the first level (so not dependencies)

npm -g ls --depth=0

which should output something like this

/usr/local/lib
└── gatsby-cli@1.1.58

Step 4 - Huzzah

Success! Now you can use gatsby in all its loveliness.

gatsby new lovely-gatsby-site

@Tokhirjon
Copy link

thansk worked for me

@BladimirDelBarrioPizarro

@ bfeldman89 Aquí están los pasos que tomé que resolvieron el problema para mí también en base a los pasos de @pereiraryan .

Paso 1 - Establecer configuración

Si está usando nvm, quiere usar

npm config eliminar prefijo

ya nvmque no es compatible con la opción "prefijo" de configuración npm.

De lo contrario, si no usa nvm, simplemente puede ejecutar

npm config set prefix / usr / local

Paso 2 - Instala Gatsby

Instalar gatsbyglobalmente connpm

npm i -g gatsby-cli

Paso 3: verificar la instalación

Verifique que gatsby esté instalado correctamente enumerando todos los paquetes que ha instalado globalmente en el primer nivel (por lo tanto, no dependencias)

npm -g ls --depth = 0

que debería generar algo como esto

/ usr / local / lib 
└── gatsby-cli@1.1.58

Paso 4 - Huzzah

¡Éxito! Ahora puedes usarlo gatsbyen toda su belleza.

gatsby new lovely-gatsby-site

Eres un subnormal qu eno tiene ni puta idea. La qu ehe liado por tú culpa.Inútil!

@ganeshbhandarkar
Copy link

npm WARN deprecated @hapi/joi@15.1.1: joi is leaving the @Hapi organization and moving back to 'joi' (hapijs/joi#2411)
npm WARN deprecated @hapi/address@2.1.4: This version has been deprecated and is no longer supported or maintained
npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
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 chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated graphql-import@0.7.1: GraphQL Import has been deprecated and merged into GraphQL Tools, so it will no longer get updates. Use GraphQL Tools instead to stay up-to-date! Check out https://www.graphql-tools.com/docs/migration-from-import for migration and https://the-guild.dev/blog/graphql-tools-v6 for new changes.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/gatsby/node_modules/babel-plugin-add-module-exports/node_modules/chokidar/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.2 (node_modules/gatsby/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"})

npm ERR! Unexpected end of JSON input while parsing near '...cies":{"react":"^16.1'

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-08-14T12_54_33_674Z-debug.log

what should i do

@gurudattapatil
Copy link

Does npm -g ls --depth=0 list gatsby-cli as being installed?

When i use npm install -g gatsby-cli, it works on one terminal fine but after i close that terminal and work on other terminal it dosen't work. And dosent showing in npm -g ls --depth=0

@Godswill199
Copy link

Does npm -g ls --depth=0 list gatsby-cli as being installed?

It said "empty" in my terminal, Do you have a solution for it?

@rshah9
Copy link

rshah9 commented Sep 15, 2020

GATSBY FUCKING SUKS! you install the cli and then it fducking doesnt find gatsby command!!???

@SSylvain1989
Copy link

SSylvain1989 commented Dec 6, 2020

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

@jamo
Copy link
Contributor

jamo commented Dec 6, 2020

To avoid having to use sudo when installing node dependencies it's recommended to use tools like https://github.com/nvm-sh/nvm to install a specific node version locally.

@SSylvain1989 Nothing in the blockquote seem like it's actually erroring (lots of warning are printed though). What's the error you are running into? (Please share full output even if it's hundreds of lines)

@SSylvain1989
Copy link

Hello @jamo for this moment all works fine for me 😄

i have follow the instructions you mentionned and outpout is like below , so i think i'm ok ? 😃 ( sorry for my bad english talk ):

    /mnt/c/Users/Sylvain/test-gatsby  on   master                                              at 19:03:50  
❯ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13527  100 13527    0     0  54765      0 --:--:-- --:--:-- --:--:-- 54765
=> Downloading nvm from git to '/home/sylvain/.nvm'
=> Cloning into '/home/sylvain/.nvm'...
remote: Enumerating objects: 333, done.
remote: Counting objects: 100% (333/333), done.
remote: Compressing objects: 100% (283/283), done.
remote: Total 333 (delta 38), reused 150 (delta 25), pack-reused 0
Receiving objects: 100% (333/333), 177.11 KiB | 740.00 KiB/s, done.
Resolving deltas: 100% (38/38), done.
=> Compressing and cleaning up git repository

=> Appending nvm source string to /home/sylvain/.bashrc
=> Appending bash_completion source string to /home/sylvain/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

    /mnt/c/Users/Sylvain/test-gatsby  on   master                                  took 6s   at 19:05:28  
❯ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
=> nvm is already installed in /home/sylvain/.nvm, trying to update using git
=> => Compressing and cleaning up git repository

=> nvm source string already in /home/sylvain/.bashrc
=> bash_completion source string already in /home/sylvain/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

@shortdark
Copy link

shortdark commented Mar 13, 2021

I had this problem when I ran npm i -g gatsby-cli and was told to upgrade nodejs. After upgrading node, the gatsby command didn't work (but npm run build did).

All I did to fix was run npm i -g gatsby-cli a second time.

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