DEV Community

Yu Hamada
Yu Hamada

Posted on

Setting Up of Supabase CLI and Local Environment

Table of Contents

The benefits and strenghs of developing locally with Supabase

  • Supabase allows us to recreate a virtual environment on our local PC for each project.

  • We can push and apply the database schema, auth policies, and other configurations developed in our local environment to the remote production environment.

  • Supabase provides commands for setting up a local environment, allowing us to simply run these commands to create a virtual environment within Docker. These commands are Supabase CLI!

Image description

Prerequisites

  • Node.js and npm installed
  • Docker Installed(Supabase local environment relies on Docker)

Step 1: Installing Supabase CLI

  1. Run the following command to install Supabase CLI globally

when using npm

npm install -g supabase 
Enter fullscreen mode Exit fullscreen mode

when using Homebrew(macOS)

brew install supabase/tap/supabase
Enter fullscreen mode Exit fullscreen mode
  1. verify the installation by running
supabase --version
> 2.2.1
Enter fullscreen mode Exit fullscreen mode

Step 2: Creating a New Supabase Project

  1. Create a new directory and navigate into it
mkdir my-supabase-project  
cd my-supabase-project
supabase login  
Enter fullscreen mode Exit fullscreen mode
  1. Initialize a Supabase project
supabase init
Enter fullscreen mode Exit fullscreen mode

Step 3: Starting the Local Environment

  1. Ensure Docker is running
  2. Start the Supabase local environment with
supabase start  
Enter fullscreen mode Exit fullscreen mode
  1. Once started, the terminal will display the local environment URLs and connection details
supabase start

Started supabase local development setup.

         API URL: http://127.0.0.1:54321
     GraphQL URL: http://127.0.0.1:54321/graphql/v1
  S3 Storage URL: http://127.0.0.1:54321/storage/v1/s3
          DB URL: postgresql://postgres:postgres@127.0.0.1:54322/postgres
      Studio URL: http://127.0.0.1:54323
    Inbucket URL: http://127.0.0.1:54324
      JWT secret: <JWT SECRET>
        anon key: <ANON_KEY>
service_role key: <SERVICE_ROLE_KEY>
   S3 Access Key: <S3 ACCESS_KEY>
   S3 Secret Key: <S3 SECERT KEY>
       S3 Region: local
Enter fullscreen mode Exit fullscreen mode

When we start the local environment for the first time, it will take time as Docker images need to be downloaded.

Once the setup is complete, the following services will be available for use

  • PostgreSQL Database
  • Authentication Service (Auth)
  • Storage Service
  • Realtime Server

Step 4: Access to Supabase Studio

In local environment, we can access http://localhost:54323/project/default and see Supabase Studio.

Image description

Step 5: Connect to application

SUPABASE_URL=http://localhost:54321
SUPABASE_ANON_KEY=...
SUPABASE_SERVICE_ROLE_KEY=...
Enter fullscreen mode Exit fullscreen mode

This completes the setup of the Supabase CLI and local Supabase environment!

Other Supabase CLI Commands

Stop Supabase

supabase stop
Enter fullscreen mode Exit fullscreen mode

Reset Supabase database

supabase stop --no-backup
Enter fullscreen mode Exit fullscreen mode

Display Supabase local environment variables

supabase status
Enter fullscreen mode Exit fullscreen mode

Cannot connect to the Docker daemon error

If Docker is not running on your local machine, you'll see the following error when executing supabase start

supabase start

Cannot connect to the Docker daemon at unix:///Users/username/.docker/run/docker.sock. Is the docker daemon running?
  in github.com/supabase/cli/internal/utils.AssertDockerIsRunning:52
  in github.com/supabase/cli/internal/start.Run:38
Try rerunning the command with --debug to troubleshoot the error.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)