by Sai gowtham

How to fix the Gatsby command not found issue

In this tutorial, we are going to learn about how to fix the Gatsby: command not found issue after installing the gatsby-cli.

When we install a gatsby-cli using the npm i -g gatsby-cli command and trying to use a gatsby command sometimes we will see the following issue in our terminal.

-bash: gatsby: command not found

This issue occurs due to the mismatch of the npm config prefix option.

To fix this issue follow the below steps:

  1. First, delete the npm path prefix by running the following command.
npm config delete prefix
  1. Set a path prefix to /usr/local.
npm config set /usr/local
  1. Now, install the gatsby-cli globally by using the following command.
npm install -g gatsby-cli

Note: If you are using mac then you need to add sudo before the above command.

  1. Verify the successful installation by running the gatsby -v command.
gatsby -v

If it outputs the version number like this, then you are successfully installed.

Gatsby CLI version: 2.12.51

You can now create new gatsby projects like this.

gatsby new my-new-gatsby-blog

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course