gatsby: "Gatsby: command not found" on trying to run Gatsby command after installing npm install --global gatsby-cli

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.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 46 (7 by maintainers)

Most upvoted comments

@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

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 👍

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

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

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

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)

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

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.

@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

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