Table of Contents
- The Benefits and Strengths of Developing Locally with Supabase
- Prerequisites
- Step 1: Installing Supabase CLI
- Step 2: Creating a New Supabase Project
- Step 3: Starting the Local Environment
- Step 4: Access to Supabase Studio
- Step 5: Connect to Application
- Other Supabase CLI Commands
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!
Prerequisites
- Node.js and npm installed
- Docker Installed(Supabase local environment relies on Docker)
Step 1: Installing Supabase CLI
- Run the following command to install Supabase CLI globally
when using npm
npm install -g supabase
when using Homebrew(macOS)
brew install supabase/tap/supabase
- verify the installation by running
supabase --version
> 2.2.1
Step 2: Creating a New Supabase Project
- Create a new directory and navigate into it
mkdir my-supabase-project
cd my-supabase-project
supabase login
- Initialize a Supabase project
supabase init
Step 3: Starting the Local Environment
- Ensure Docker is running
- Start the Supabase local environment with
supabase start
- 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
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.
Step 5: Connect to application
SUPABASE_URL=http://localhost:54321
SUPABASE_ANON_KEY=...
SUPABASE_SERVICE_ROLE_KEY=...
This completes the setup of the Supabase CLI and local Supabase environment!
Other Supabase CLI Commands
Stop Supabase
supabase stop
Reset Supabase database
supabase stop --no-backup
Display Supabase local environment variables
supabase status
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.
Top comments (0)