Skip to main content

从 CLI 安装

¥Installing from CLI

Strapi CLI(命令行接口)安装脚本是让 Strapi 在本地运行的最快方法。以下指南是 Strapi 最推荐的安装选项。

¥Strapi CLI (Command Line Interface) installation scripts are the fastest way to get Strapi running locally. The following guide is the installation option most recommended by Strapi.

准备安装

¥Preparing the installation

在安装 Strapi 之前,你的计算机上必须安装以下要求:

¥Before installing Strapi, the following requirements must be installed on your computer:

  • Node.js:仅支持 活动 LTS 或维护 LTS 版本(目前支持 v18v20)。不支持 Node 的奇数版本(称为 Node.js 的 "current" 版本)(例如 v19、v21)。

    ¥Node.js: Only Active LTS or Maintenance LTS versions are supported (currently v18 and v20). Odd-number releases of Node, known as "current" versions of Node.js, are not supported (e.g. v19, v21).

  • 你首选的 Node.js 包管理器:

    ¥Your preferred Node.js package manager:

  • Python(如果使用 SQLite 数据库)

    ¥Python (if using a SQLite database)

任何 Strapi 项目还需要支持的数据库:

¥A supported database is also required for any Strapi project:

数据库最低限度受到推崇的
MySQL5.7.88.0
玛丽亚数据库10.310.6
PostgreSQL11.014.0
SQLite33
提醒

Strapi v4 不支持 MongoDB。

¥Strapi v4 does not support MongoDB.

创建 Strapi 项目

¥Creating a Strapi project

按照以下步骤创建一个新的 Strapi 项目,确保使用适合你已安装的包管理器的命令:

¥Follow the steps below to create a new Strapi project, being sure to use the appropriate command for your installed package manager:

  1. 在终端中,运行以下命令:

    ¥In a terminal, run the following command:

```bash
yarn create strapi-app my-project
# 'yarn create' creates a new project
# 'strapi-app' is the Strapi package
# 'my-project' is the name of your Strapi project
```

  1. 选择安装类型:

    ¥Choose an installation type:

    • Quickstart (recommended),使用默认数据库(SQLite)

      ¥Quickstart (recommended), which uses the default database (SQLite)

    • Custom (manual settings),允许选择你喜欢的数据库

      ¥Custom (manual settings), which allows to choose your preferred database

  2. (仅限自定义安装类型)在数据库列表中,为你的 Strapi 项目选择一个数据库。

    ¥(Custom installation type only) Among the list of databases, choose a database for your Strapi project.

  3. (仅限自定义安装类型)命名你的项目的数据库。

    ¥(Custom installation type only) Name your project's database.

CLI 安装选项

¥CLI installation options

上述安装指南仅涵盖使用 CLI 的基本安装选项。创建新的 Strapi 项目时还可以使用其他选项,例如:

¥The above installation guide only covers the basic installation option using the CLI. There are other options that can be used when creating a new Strapi project, for example:

  • --quickstart:直接以快速启动方式创建项目。

    ¥--quickstart: Directly create the project in quickstart mode.

  • --template:使用预制 Strapi 配置创建项目(参见 模板)。

    ¥--template: Create a project with pre-made Strapi configurations (see Templates).

  • --typescript/--ts:在 TypeScript 年创建一个项目。

    ¥--typescript/--ts: Create a project in TypeScript.

  • --no-run:防止 Strapi 自动启动服务器(与 --quickstart 结合使用)。

    ¥--no-run: Prevent Strapi from automatically starting the server (useful in combination with --quickstart).

有关可用标志的更多信息,请参阅我们的 CLI 文档

¥For more information on available flags, see our CLI documentation.

Strapi 还提供了一个入门 CLI,用于使用预制前端应用创建项目(请参阅 我们的专门博客文章)。

¥Strapi also offers a starters CLI to create a project with a pre-made frontend application (see our dedicated blog post).

💡 提示

实验性 Strapi 版本每周二至周六格林尼治标准时间午夜发布。你可以使用 npx create-strapi-app@experimental 基于最新实验版本创建新的 Strapi 应用。

¥Experimental Strapi versions are released every Tuesday through Saturday at midnight GMT. You can create a new Strapi application based on the latest experimental release using npx create-strapi-app@experimental.

请自行承担使用这些实验版本的风险。不建议在生产中使用它们。

¥Please use these experimental builds at your own risk. It is not recommended to use them in production.

运行 Strapi

¥Running Strapi

要启动 Strapi 应用,请在项目文件夹中运行以下命令:

¥To start the Strapi application, run the following command in the project folder:

yarn develop
👀 我的内容在哪里?

对于自托管 Strapi 项目,你的所有内容都保存在项目文件夹中 .tmp 子文件夹中的数据库文件(默认情况下为 SQLite)中。因此,只要你从创建 Strapi 项目的文件夹启动 Strapi 应用,你的内容就可用(请参阅 数据库配置 了解更多信息)。

¥For self-hosted Strapi projects, all your content is saved in a database file (by default, SQLite) found in the .tmp subfolder in your project's folder. So anytime you start the Strapi application from the folder where you created your Strapi project, your content will be available (see database configuration for additional information).

如果内容已添加到 Strapi Cloud 项目,它将存储在由你的 Strapi Cloud 项目管理的数据库中(有关更多信息,请参阅 Strapi Cloud 的高级数据库配置)。

¥If the content was added to a Strapi Cloud project, it is stored in the database managed with your Strapi Cloud project (see advanced database configuration for Strapi Cloud for additional information).