Setting up Supabase Locally
Learn how to set up Supabase locally for development. This guide will show you how to pull the Docker image and set up the environment variables for your Next.js application.
To get started with Supabase locally, you will just need to pull the docker image. Here's how to do it:
Setting up Docker for Supabase
- First, you will need to install Docker on your machine. You can download the installer from the Docker website since it is the recommended way to install Docker on Windows and macOS. If you are using Linux, you can follow the instructions for your specific distribution on the Docker documentation.
- Next, you will need to setup the env variables.
In your repository directory, you should have a .env.local.example file which looks like this. For dev environment, copy the .env.local.example file to .env.local. The localhost values are used for local development. However, you will need to update NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY and SUPABASE_SECRET_KEY with the actual values from pnpm supabase status after starting Supabase (see step 4 below).
# supabase
# Get the actual publishable key and secret key from `pnpm supabase status` after starting Supabase
NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321/
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=YOUR_PUBLISHABLE_KEY
SUPABASE_SECRET_KEY=YOUR_SECRET_KEY
SUPABASE_DATABASE_PASSWORD=postgres
SUPABASE_JWT_SECRET=super-secret-jwt-token-with-at-least-32-characters-long
# SUPABASE_PROJECT_REF=SUPABASE_PROJECT_REF
# stripe
STRIPE_SECRET_KEY=STRIPE_SECRET_KEY
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY
STRIPE_WEBHOOK_SECRET=STRIPE_WEBHOOK_SECRET
# host
NEXT_PUBLIC_SITE_URL=http://localhost:3000
# email
ADMIN_EMAIL=admin@myapp.com
RESEND_API_KEY=RESEND_API_KEY
# analytics
# ultimate and pro
NEXT_PUBLIC_POSTHOG_API_KEY=NEXT_PUBLIC_POSTHOG_API_KEY
NEXT_PUBLIC_POSTHOG_APP_ID=NEXT_PUBLIC_POSTHOG_APP_ID
NEXT_PUBLIC_POSTHOG_HOST=NEXT_PUBLIC_POSTHOG_HOST
NEXT_PUBLIC_GA_ID=NEXT_PUBLIC_GA_ID
UNKEY_ROOT_KEY=UNKEY_ROOT_KEY
UNKEY_API_ID=UNKEY_API_ID
## Supabase providers
# this file is only used by supabase configtoml for local development
# next.js uses .env.local for local development
TWITTER_API_KEY=TWITTER_API_KEY
TWITTER_API_SECRET=TWITTER_API_SECRET
GOOGLE_CLIENT_ID=GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET=GOOGLE_CLIENT_SECRET
GITHUB_CLIENT_ID=GITHUB_CLIENT_ID
GITHUB_CLIENT_SECRET=GITHUB_CLIENT_SECRETNote. Supabase also reads from .env.local for local development. If you don't need to setup social providers like github, google yet, just leave the dummy values in env.local file. Removing the values will however break supabase start, since the config.toml has social providers enabled by default. Either disable them in config.toml or leave the dummy values. Read more here.
- Once you have Docker installed and running in your machine, you can now pull the Supabase Docker image by running
pnpm supabase startin your terminal.
Please note that for the first time you run the
pnpm supabase startcommand, it will take some time to pull the Docker image. Subsequent runs will be faster since the images will be cached and volumes will be persisted.
- After running the command, you should see the output simmilar to the following:
Status: Downloaded newer image for public.ecr.aws/supabase/studio
Started supabase local development setup.
API URL: http://localhost:54321
GraphQL URL: http://localhost:54321/graphql/v1
DB URL: postgresql://postgres:postgres@localhost:54322/postgres
Studio URL: http://localhost:54323
Inbucket URL: http://localhost:54324
JWT secret: super-secret-jwt-token-with-at-least-32-characters-long
publishable key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
secret key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...Important: Copy the publishable key and secret key values from the terminal output above and update your .env.local file:
- Set
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEYto thepublishable keyvalue - Set
SUPABASE_SECRET_KEYto thesecret keyvalue
You can also run pnpm supabase status at any time to see these values again.
- You can now access the Supabase Studio by visiting the URL
http://localhost:54323in your browser. - You can also access the API and GraphQL URLs to interact with your local Supabase instance.
- To connect database clients to your local Supabase instance, you can use the DB URL
postgresql://postgres:postgres@localhost:54322/postgres - To monitor your inboxes, you can use the Inbucket URL
http://localhost:54324 - You can stop the Supabase server by running the
pnpm supabase stopcommand, to save on system resources.