Skip to main content

Setting Up Supabase Locally

This guide will help you set up a local Supabase instance for development.

Prerequisites

  • Docker installed and running
  • Project cloned and dependencies installed

Steps

  1. Navigate to Supabase Package

    cd packages/supabase
  2. Start Supabase Services

    npx supabase start

    This command will:

    • Pull required Docker images
    • Start the Supabase services
    • Apply migrations
    • Generate types
  3. Verify the Setup

    Once started, you can access:

    • Supabase Studio: http://localhost:54323
    • Database: postgresql://postgres:postgres@localhost:54322/postgres
    • API URL: http://localhost:54321
  4. Configure Environment Variables

    Copy the environment variables from your local Supabase instance:

    # From packages/supabase
    cp .env.example .env

    Update .env with your local Supabase credentials:

    NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321
    NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
    SUPABASE_SERVICE_ROLE_KEY=your-service-role-key

    You can find these values in the output of npx supabase start or in Supabase Studio.

Development Workflow

  1. Start Development Environment

    # From project root
    pnpm dev
  2. Create and Apply Migrations

    When making database changes:

    # Create a new migration
    npx supabase migration new my_change

    # Apply migrations
    npx supabase db reset
  3. Generate Types

    After schema changes:

    pnpm generate:types

Common Commands

All commands should be run from packages/supabase:

# Start Supabase
npx supabase start

# Stop Supabase
npx supabase stop

# Reset database
npx supabase db reset

# View database changes
npx supabase db diff

# Create new migration
npx supabase migration new my_migration

Troubleshooting

  1. Docker Issues

    • Ensure Docker is running
    • Try stopping and removing containers:
      npx supabase stop
      docker-compose down
  2. Database Connection Issues

    • Check if ports 54321-54323 are available
    • Verify Docker network settings
    • Ensure environment variables are correct
  3. Migration Problems

    • Reset the database: npx supabase db reset
    • Check migration files for syntax errors
    • Verify migration order

Next Steps

  1. Create your first migration
  2. Set up authentication
  3. Configure email templates