How to Install Gatsby CLI and Deploy a Gatsby Project on Ubuntu?

Gatsby is a powerful, open-source static site generator built on React. It’s widely used for creating fast, modern websites and web applications. Gatsby offers optimized performance, strong SEO capabilities, and seamless developer experience.

In this guide, we’ll walk you through installing the Gatsby CLI and deploying a Gatsby project on an Ubuntu-based system.

Prerequisites

Before you begin, ensure the following are in place:

  • A server running Ubuntu
  • A user account with sudo privileges
  • Node.js installed on your system

 

Step 1: Install Gatsby CLI

Start by updating your system packages:

sudo apt update

Next, install Gatsby CLI globally using npm:

npm install -g gatsby-cli

To verify the installation was successful, run:

gatsby --version

 

Step 2: Create a New Gatsby Project

Create a new Gatsby site by running:

gatsby new my-gatsby-site

Navigate into the project directory:

cd my-gatsby-site

 

Step 3: Start the Gatsby Development Server

To launch the development environment, execute:

gatsby develop

Your development server should now be live at:

http://localhost:8000

 

Step 4: Build the Gatsby Project for Production

To create a production-ready build of your site, run:

gatsby build

This generates an optimized version of your project for deployment.

 

Step 5: Serve the Gatsby Production Build

To preview your site as it would appear in production, run:

gatsby serve

The production server will be available at:

http://localhost:9000

 

Conclusion

You’ve now successfully installed the Gatsby CLI on Ubuntu, created a new project, run a development server, built the project for production, and served it locally. Gatsby provides an efficient, scalable way to build high-performance websites and applications that are ready for search engine indexing and fast user experiences.

Facebook
Twitter
LinkedIn
Reddit
WhatsApp
Telegram
Email
Print