本地开发与命令行工具
Learn how to develop locally and use the Supabase CLI
要使用本地运行的 Supabase 堆栈来开发你的应用,你需要安装 Supabase CLI 和一个容器运行环境。
🌐 To develop your applications using the locally running Supabase stack, you'll need to install the Supabase CLI and a container runtime.
与 Docker API 兼容的容器管理器是 supabase start 的前提条件:
🌐 A container manager compatible with Docker APIs is a prerequisite for supabase start:
- OrbStack(macOS)- 在 macOS 上推荐
- Docker Desktop(macOS、Windows、Linux)- 推荐在 Windows 和 Linux 上使用
- Rancher Desktop(macOS、Windows、Linux)
- Podman(macOS、Windows、Linux)
实验性的 supabase stack 命令也可以在 Linux 上,以及在配备 Apple 芯片的 macOS 上,不使用 Docker 的情况下,将本地项目作为进程运行在你的机器上。详见 Docker 和本地运行环境。
🌐 The experimental supabase stack commands can also run a local project as processes on your machine without Docker on Linux and on macOS on Apple silicon. See Docker and native runtimes.
快速入门 #
🌐 Quickstart
选择一种安装方法,并在下列每一步中使用相同的标签。Homebrew 会给你一个全局的 supabase 命令。npm、pnpm 和 yarn 会把 CLI 安装到你的项目中作为开发依赖,因此你需要通过你的包管理器运行它(npx supabase、pnpm supabase 或 yarn supabase)。详情请看 安装和运行 CLI。
🌐 Pick an install method and use the same tab in every step below. Homebrew gives you a global supabase command. npm, pnpm, and yarn install the CLI into your project as a dev dependency, so you run it through your package runner (npx supabase, pnpm supabase, or yarn supabase). See Install and run the CLI for details.
-
安装 Supabase CLI:
npm install supabase --save-dev -
在你的仓库里,初始化本地 Supabase 项目:
npx supabase init -
启动本地 Supabase 堆栈:
npx supabase start -
在本地通过 http://localhost:54323 查看你的 Supabase 实例。
如果你的本地开发机器连接到不受信任的公共网络,你应该在启动本地开发环境之前创建一个独立的 Docker 网络,并绑定到 127.0.0.1。这会将网络访问限制在你的本地主机上。
🌐 If your local development machine is connected to an untrusted public network, you should create a separate Docker network and bind to 127.0.0.1 before starting the local development stack. This restricts network access to only your localhost machine.
docker network create -o 'com.docker.network.bridge.host_binding_ipv4=127.0.0.1' local-networknpx supabase start --network-id local-network你绝不应该把本地开发环境公开暴露。
🌐 You should never expose your local development stack publicly.
本地开发 #
🌐 Local development
使用 Supabase 进行本地开发可以让你在本地计算机的独立环境中进行项目开发。在本地工作有几个好处:
🌐 Local development with Supabase allows you to work on your projects in a self-contained environment on your local machine. Working locally has several advantages:
- 更快的开发:你可以马上做出更改并看到结果,无需等待远程部署。
- 离线工作:即使没有网络连接,你也可以继续开发。
- 性价比高:本地开发是免费的,而且不会消耗你项目的配额。
- 增强隐私:开发过程中敏感数据会保留在你的本地机器上。
- 安全测试:你可以尝试不同的配置和功能,而不会影响你的生产环境。
一旦设置好,你就可以初始化一个新的 Supabase 项目,启动本地环境,并开始使用本地 Supabase 服务开发你的应用。这包括访问本地 Postgres 数据库、认证、存储以及其他 Supabase 功能。
🌐 Once set up, you can initialize a new Supabase project, start the local stack, and begin developing your application using local Supabase services. This includes access to a local Postgres database, Auth, Storage, and other Supabase features.
使用默认端口时,supabase start 每台机器只能运行一个本地项目。要同时为每个应用或 git 工作树运行本地项目,可以使用在 运行多个本地项目 中描述的实验性 supabase stack 命令。
🌐 With the default ports, supabase start runs one local project per machine. To run a local project for each app or git worktree at the same time, use the experimental supabase stack commands described in Running multiple local projects.
命令行接口 #
🌐 CLI
Supabase CLI 是一个工具,允许开发者在本地运行 Supabase 服务,并直接从终端管理托管的项目。它提供了一套用于各种任务的命令,包括:
🌐 The Supabase CLI is a tool that enables developers to run Supabase services locally and manage hosted projects directly from the terminal. It provides a suite of commands for various tasks, including:
使用命令行工具,你可以简化开发工作流程、自动化重复任务,并在不同环境中保持一致性。这是本地开发和 CI/CD 流水线中都必不可少的工具。
🌐 With the CLI, you can streamline your development workflow, automate repetitive tasks, and maintain consistency across different environments. It's an essential tool for both local development and CI/CD pipelines.
请查看CLI入门指南了解更多信息。
🌐 See the CLI Getting Started guide for more information.