2. Setting up Supabase Locally
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.
- Once you have Docker installed and running in your machine, you can now pull the Supabase Docker image by running
pnpm supabase start
in your terminal.
Please note that for the first time you run the
pnpm supabase start
command, 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
anon key: anon-key-for-local-development
service_role key: service-role-key-for-local-development
- You can now access the Supabase Studio by visiting the URL
http://localhost:54323
in 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 also use the JWT secret, anon key, and service role key for local development.
- You can stop the Supabase server by running the
pnpm supabase stop
command, to save on system resources.
Setting up .env.local for Supabase
To connect your Next.js application to your local Supabase instance, you will need to create a .env.local
file in the root of your project and add the following environment variables:
# These values never change when supabase is ran locally regardless of project
NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321/
NEXT_PUBLIC_SUPABASE_ANON_KEY=anon-key-for-local-development
SUPABASE_SERVICE_ROLE_KEY=service-role-key-for-local-development
SUPABASE_DATABASE_PASSWORD=postgres
SUPABASE_JWT_SECRET=super-secret-jwt-token-with-at-least-32-characters-long
SUPABASE_PROJECT_REF=SUPABASE_PROJECT_REF