The Supabase CLI Cheatsheet Every Dev Should Bookmark
Every Supabase CLI command that actually matters: local dev, migrations, secrets, edge functions, and troubleshooting.
The Supabase CLI is the fastest way to move a Supabase project from prototype to production. This cheatsheet covers every command that actually matters in day-to-day work — local dev, migrations, edge functions, secrets, and troubleshooting.
Install
# macOS
brew install supabase/tap/supabase
# Any OS via npm
npm i -g supabase
# Verify
supabase --versionProject setup
supabase init # create supabase/ folder
supabase login # authenticate
supabase link --project-ref <ref> # link local to cloudThe project ref is in your dashboard URL. Once linked, migrations and function deploys target that project.
Local development
supabase start # boots Docker Postgres + services
supabase stop # tears down containers
supabase status # shows local URL + anon key
supabase db reset # drops and reruns all migrations + seedsupabase start also launches Studio at http://localhost:54323 — the same UI as the hosted dashboard.
Migrations
supabase migration new add_posts_table
# edit the generated supabase/migrations/*.sql
supabase db reset # apply locally
supabase db push # deploy to linked project
supabase db pull # pull remote schema into a local migration
supabase migration list # see applied vs pendingAlways commit migrations to git before pushing. Never edit an already-applied migration file — write a new one.
Edge functions
supabase functions new hello
supabase functions serve hello --env-file .env.local
supabase functions deploy hello
supabase functions delete helloUse --no-verify-jwt on public webhooks (Stripe, GitHub) because their POSTs will not include a Supabase JWT.
Secrets
supabase secrets list
supabase secrets set STRIPE_KEY=sk_live_...
supabase secrets unset STRIPE_KEY
supabase secrets set --env-file .env.productionSecrets are per-project and injected into edge functions at runtime — Deno.env.get("STRIPE_KEY").
Types generation
supabase gen types typescript --linked > src/types/db.tsRun this after every migration and check it into git. Your TypeScript client will be fully typed against the schema.
Troubleshooting
Docker daemon not running— start Docker Desktop, thensupabase start.- Port conflict — another Postgres is on 54322.
lsof -i :54322to find it, or change ports insupabase/config.toml. function returned non-2xx status— checksupabase functions serveoutput; the SDK hides the real error body. Readerror.context.text()in the browser to see it.- Migration order wrong — never rename applied migration files. Use
supabase migration repairif a manual dashboard change has drifted.
Final Thoughts
Every decision in this guide should map back to one question: *what will make the next six months of shipping easier?* Pick the tool that removes the most friction for your team today, and revisit the choice when the constraints change.
If you want an experienced team to ship this for you, Devloader builds production apps across Laravel, Next.js, and Supabase. See our portfolio or request a quote.
Key takeaways
- The Supabase CLI is essential for efficient local development and cloud integration.
- Mastering the Supabase CLI boosts productivity across database, functions, and authentication workflows.
- Leverage
supabase db resetfor quick local schema iterations. - Generate TypeScript types with the Supabase CLI to maintain strong type safety.
- Employ
supabase secretsfor secure management of sensitive environment variables.
Optimizing Your Supabase Workflow with the CLI
The Supabase CLI acts as a developer's direct interface to their Supabase projects, both locally and in the cloud. By integrating the Supabase CLI into daily development, teams can significantly streamline common tasks such as schema migrations, deploying edge functions, and managing environment variables. This direct command-line access minimizes friction, ensuring that developers can focus more on building features and less on navigating dashboards.
Efficient use of the Supabase CLI also supports continuous integration/continuous deployment (CI/CD) pipelines. Commands like supabase db push and supabase functions deploy can be easily scripted, enabling automated deployments that are consistent and reliable. This capability is crucial for maintaining a rapid development cycle and ensuring that changes are thoroughly tested before reaching production environments.
Real-world example: Deploying a Multi-Region API
Imagine a team at "GlobalCo" needing to deploy a new API feature across several geographic regions using Supabase Edge Functions. Their primary goal is low latency for users worldwide. Manually configuring each region would be error-prone and slow.
Here's how the Supabase CLI helps:
- Develop Locally: A developer creates the new API function,
create_user_profile, locally usingsupabase functions new create_user_profile. They test it rigorously usingsupabase functions serve create_user_profile --env-file .env.local. - Database Migrations: The new API requires a
user_profilestable. The developer generates a migration script withsupabase migration new create_user_profiles_table.sql, defines the schema, and applies it locally withsupabase db reset. - Deploy Globally: Once local testing is complete, the developer pushes the database schema to the linked Supabase project using
supabase db push. Then, they deploy the edge function to the serverless network withsupabase functions deploy create_user_profile. Supabase handles the global distribution automatically. - Performance Monitoring: Post-deployment, the team uses Supabase's built-in logging and monitoring tools, alongside their custom dashboards, to ensure
create_user_profilemaintains sub-50ms latency across all regions.
This approach saves "GlobalCo" dozens of hours in manual configuration, reduces deployment risks, and ensures optimal performance for their global user base.
Step-by-step implementation: Initiating a New Supabase Project
To start a new project with the Supabase CLI, follow these steps to ensure a smooth setup from local development to cloud deployment.
- Install the Supabase CLI: First, ensure the CLI is installed on your system.
brew install supabase/tap/supabase # macOS- Initialize Project Directory: Navigate to your project's root directory and initialize Supabase. This creates the
supabase/directory with configurations.
supabase init- Authenticate Your CLI: Log in to your Supabase account. This connects your local CLI to your Supabase cloud dashboard.
supabase login- Create a New Supabase Project: Head to the Supabase dashboard in your browser and create a new project. Note down its project reference ID from the URL.
- Link Local to Cloud Project: Link your local setup to your newly created cloud project using its reference ID.
supabase link --project-ref your-project-ref-id- Start Local Development Environment: Boot up the local Docker-based Supabase services, including Postgres and Studio.
supabase start- Create Your First Migration: Generate a new migration file to define your database schema.
supabase migration new initial_schema_setup- Apply and Push Migrations: After editing the
.sqlfile, apply the migration locally withsupabase db reset, then push it to your linked cloud project withsupabase db push.
Common pitfalls and how to fix them
- Pitfall: Conflicting ports when running
supabase start. Fix: Modifysupabase/config.tomlto change the default ports (e.g.,db_port = 54323,rest_port = 54324) or identify and terminate the conflicting process usinglsof -i :<port>. - Pitfall: Edge functions failing with a generic "function returned non-2xx status" error. Fix: Simulate the function locally using
supabase functions serve <func_name> --env-file .env.localto get detailed error messages directly in your terminal. For browser-based calls, inspecterror.context.text()for the real upstream error. - Pitfall: Database schema drift between local and remote environments, leading to
supabase db pushfailures. Fix: Regularly usesupabase db pullto get the latest remote schema as a migration, or manually fix inconsistencies withsupabase migration repairif accidental dashboard changes occurred. - Pitfall: Outdated TypeScript types for your database schema after a migration. Fix: Always rerun
supabase gen types typescript --linked > src/types/db.tsafter every successfulsupabase db pushto keep your client code fully synchronized and type-safe. - Pitfall: Secrets failing to load in edge functions. Fix: Ensure secrets are set per-project using
supabase secrets set KEY=VALUEand confirm they appear insupabase secrets list. Remember secrets are injected at runtime, so test deployments thoroughly.
When to use this vs. alternatives
The Supabase CLI excels for integrated and rapid development within the Supabase ecosystem, particularly for full-stack JavaScript/TypeScript projects.
Feature — Supabase CLI — Manual Dashboard/API
Local Development — Fully functional local Supabase instance (Postgres, Auth, Storage, Edge Functions) — Requires manual setup of local services or continuous cloud-only deployment
Database Migrations — Version-controlled SQL migrations, db reset, db push, db pull — Direct schema changes via SQL editor, not version-controlled
Edge Function Deployment — supabase functions deploy for CI/CD and atomic deployments — Manual upload of code via dashboard or custom scripting against API
Secrets Management — supabase secrets for secure, scriptable environment variable management — Manual entry in dashboard, less suitable for automated pipelines
Type Generation — supabase gen types for strongly typed client-side code — Manual creation of types, error-prone and time-consuming
CI/CD Integration — High, commands are designed for scripting and automation — Low, relies on UI interactions or complex API calls
While the Supabase dashboard offers a great visual overview and simple configuration, the Supabase CLI is irreplaceable for developers prioritizing speed, automation, and consistent environments. For complex deployments or a high-paced development cycle, the CLI offers unmatched control and efficiency compared to manual interactions.
FAQ
What is the primary function of the Supabase CLI?
The primary function of the Supabase CLI is to provide a command-line interface for interacting with your Supabase projects, enabling developers to manage local development environments, deploy changes to the cloud, and automate various tasks. It acts as a bridge between your local codebase and your hosted Supabase infrastructure.
How do I connect my local project to a remote Supabase instance?
You connect your local project to a remote Supabase instance by first authenticating with supabase login, then linking your local directory to a specific project using supabase link --project-ref <your-project-ref-id>. The project reference ID can be found in your Supabase dashboard URL.
Can I run Supabase locally without Docker?
No, the core Supabase services like Postgres, Auth, and Storage require Docker containers to run locally via supabase start. Docker Desktop or a compatible Docker environment must be installed and running for local development with the Supabase CLI.
How do I manage environment variables (secrets) for my Supabase Edge Functions?
You manage secrets for your Supabase Edge Functions using the supabase secrets commands. You can list existing secrets, set new ones with supabase secrets set KEY=VALUE, and unset them as needed. These secrets are securely injected into your functions at runtime.
What is the purpose of supabase gen types typescript?
supabase gen types typescript generates TypeScript definitions for your Supabase database schema. This allows your client-side code, especially when using the Supabase JavaScript client library, to have strong type checking against your database tables, views, and functions, improving development reliability.
What should I do if my supabase db push fails?
If supabase db push fails, first ensure your local schema is aligned with the remote one. Consider pulling remote changes with supabase db pull or inspecting error messages related to migration conflicts. Always commit your migrations to version control before pushing to avoid data loss.
Related concepts
- PostgreSQL: The underlying relational database technology powering Supabase, with strong ACID compliance and extensive features for data management.
- Docker: Containerization platform essential for running Supabase's local development environment, ensuring consistent setup across different machines.
- Deno: The JavaScript/TypeScript runtime environment used for executing Supabase Edge Functions, offering modern web APIs and secure sandboxed execution.
- GitHub Actions: A popular CI/CD platform that can be integrated with the Supabase CLI to automate deployments, run tests, and manage infrastructure changes.
- Next.js Authentication: A common use case where Supabase Auth and database features are integrated, often requiring careful management of environment variables and types generated by the CLI.