从 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 版本(目前支持
v20
和v22
)。不支持 Node 的奇数版本(称为 Node.js 的 "current" 版本)(例如 v21、v23)。¥Node.js: Only Active LTS or Maintenance LTS versions are supported (currently
v20
andv22
). Odd-number releases of Node, known as "current" versions of Node.js, are not supported (e.g. v21, v23). -
你首选的 Node.js 包管理器:
¥Your preferred Node.js package manager:
-
Python(如果使用 SQLite 数据库)
¥Python (if using a SQLite database)
A supported database is also required for any Strapi project:
数据库 | 受到推崇的 | 最低限度 |
---|---|---|
MySQL | 8.4 | 8.0 |
玛丽亚数据库 | 11.4 | 10.3 |
PostgreSQL | 17.0 | 14.0 |
SQLite | 3 | 3 |
Strapi 不支持 MongoDB(或任何 NoSQL 数据库),也不支持任何 "云原生" 数据库(例如 Amazon Aurora、Google Cloud SQL 等)。
¥Strapi does not support MongoDB (or any NoSQL databases), nor does it support any "Cloud Native" databases (e.g., Amazon Aurora, Google Cloud SQL, etc.).
创建 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:
-
在终端中,运行以下命令:
¥In a terminal, run the following command:
- NPM
- Yarn
- pnpm
```bash
npx create-strapi@latest
```
Additional explanations for the command:
* `npx` runs a command from a npm package
* `create-strapi` is the Strapi package
* `@latest` indicates that the latest version of Strapi is used
<br/>
Instead of npx, the traditional npm command can be used too, with `npm create strapi@latest`.
Please note the additional dash between create and strapi when using npx: `npx create-strapi` vs. `npm create strapi`.
```bash
yarn create strapi
```
:::note
Yarn does not support passing the version tag such as `@latest`, as opposed to npm. If you experience unexpected results with yarn and the latest version of Strapi is not installed, you might need to <ExternalLink to="https://yarn.nodejs.cn/cli/cache/clean" text="run the `yarn cache clean` command"/> to clean your Yarn cache.
:::
:::caution
You might have issues with projects created with pnpm on Strapi Cloud. Strapi Cloud does not support pnpm yet, so it's recommended to use yarn or npm if you plan to eventually host your project on Strapi Cloud.
:::
```bash
pnpm create strapi
```
-
终端将询问你是否要执行此步骤的
Login/Signup
或Skip
。使用箭头键并按Enter
进行选择。如果你选择登录,你将获得 GrowthThis feature is available with a Growth plan. 计划的 30 天试用版,该试用版将自动应用于你创建的项 目。如果你跳过此步骤,项目将恢复为 CMS 免费计划。¥The terminal will ask you whether you want to
Login/Signup
orSkip
this step. Use arrow keys and pressEnter
to make your choice. If you choose to login, you'll receive a 30-day trial of the GrowthThis feature is available with a Growth plan. plan that will be automatically applied to your created project. If you skip this step, the project will fall back to the CMS Free plan. -
终端会问你几个问题。对于每个日志项,如果你按
Enter
而不是输入内容,则将使用默认答案(是):¥The terminal will ask you a few questions. For each of them, if you press
Enter
instead of typing something, the default answer (Yes) will be used:
table for the full list of available options. :::你可以使用传递给安装命令的各种选项跳过这些问题。请参考
-
(可选)如果你对默认(SQLite)数据库问题的 "no" 回答了
n
,CLI 将询问有关数据库的更多问题:¥(optional) If you answered
n
for "no" to the default (SQLite) database question, the CLI will ask for more questions about the database:-
使用箭头键选择所需的 数据库类型,然后按
Enter
。¥Use arrow keys to select the database type you want, then press
Enter
. -
为数据库命名,定义数据库主机地址和端口,定义数据库管理员用户名和密码,并定义数据库是否使用 SSL 连接。
对于这些问题中的任何一个,如果你按Enter
而不输入任何内容,则将使用默认值(在终端输出中的括号中指示)。¥Give the database a name, define the database host address and port, define the database admin username and password, and define whether the database will use a SSL connection.
For any of these questions, if you pressEnter
without typing anything, the default value (indicated in parentheses in the terminal output) will be used.
-
回答完所有问题后,脚本将开始创建 Strapi 项目。
¥Once all questions have been answered, the script will start creating the Strapi project.
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:
选项 | 描述 |
---|---|
--no-run | 不要在创建应用后启动它 |
--ts --typescript | 使用 TypeScript 初始化项目(默认) |
--js --javascript | 使用 JavaScript 初始化项目 |
--use-npm |