本指南涵盖开发环境下的安装说明。如需生产环境指南,请参阅:Install Discourse in production with the official supported instructions
您想在 Ubuntu 或 Debian 上搭建 Discourse 并进行开发吗?
我们假设您在本地工作,且您的 Ubuntu 或 Debian 系统上尚未安装 Ruby/Rails/Postgres/Redis。让我们开始吧!
要求
我们建议至少拥有 4 GB 内存和 2 个 CPU 核心。
当前兼容性:
| 操作系统 | 兼容性 |
|---|---|
| Debian 11 | |
| Crostini(ChromeOS 上的 Linux) | |
| Ubuntu 22.04 或更高版本 |
安装 Discourse 依赖项
您的系统需要以下软件包:
- Git
- rbenv 或 asdf
- ruby-build
- Ruby(最新稳定版)
- Rails
- PostgreSQL
- SQLite
- Redis
- Node.js
- pnpm
- MailHog***
- ImageMagick***
*** 可选
现在我们已经安装了 Discourse 的依赖项,让我们开始安装 Discourse 本身。
克隆 Discourse
在 ~/discourse 文件夹中克隆 Discourse 仓库:
git clone https://github.com/discourse/discourse.git ~/discourse
~ 表示主文件夹,因此 Discourse 源代码将位于您的主文件夹中。
设置数据库
创建一个与您的 Linux 系统用户名相同的角色:
cd /tmp && sudo -u postgres createuser -s "$USER"
[/details]
初始化 Discourse
切换到您的 Discourse 文件夹:
cd ~/discourse
安装所需的 gems:
source ~/.bashrc
bundle install
安装 JS 依赖项:
pnpm install
现在您已经成功安装了 gems,请运行以下命令:
bin/rails db:create
bin/rails db:migrate
RAILS_ENV=test bin/rails db:create db:migrate
启动 Rails 和前端打包工具:
bin/dev
如果图片未显示,请使用以下命令代替:
(如果您在远程服务器上工作,也可以指定 IP 地址)
DISCOURSE_HOSTNAME=localhost UNICORN_LISTENER=localhost:3000 bin/dev
现在您应该可以访问 http://localhost:3000 查看您的本地 Discourse 安装。
创建新管理员
要创建新管理员,请运行以下命令:
bin/rails admin:create
按照提示操作,即可创建一个新的管理员账户。
配置邮件
运行 MailHog:
mailhog
恭喜!您现在已成为自己 Discourse 安装的管理员!
愉快开发!要开始入门,请参阅 Discourse 插件创建初学者指南。
最后由 @blake 于 2023-04-03T06:00:00Z 审阅
本文档受版本控制 - 请在 GitHub 上提出修改建议。