在 macOS 上安装 Discourse 进行开发

:warning: 本指南介绍 macOS 开发环境的安装说明。如需生产环境指南,请访问:Install Discourse in production with the official supported instructions

您想在 macOS 上设置 Discourse 以进行开发吗?

我们将假设您的 Mac 上尚未安装 Ruby/Rails/Postgres/Redis。让我们开始吧 :rocket:

安装 Discourse 依赖项

您的系统需要以下软件包:

** 可选

重启您的终端

安装完 Discourse 依赖项后,让我们继续安装 Discourse 本身。

重启您的终端

退出并重新启动 shell 可确保终端正确识别已安装软件包的路径。

克隆 Discourse

将 Discourse 仓库克隆到 ~/discourse 文件夹:

git clone https://github.com/discourse/discourse.git ~/discourse

~ 表示主文件夹,因此 Discourse 源代码将位于您的主文件夹中。

引导 Discourse

切换到您的 Discourse 文件夹:

cd ~/discourse

安装所需的 gem:

bundle install

安装 JS 依赖项:

pnpm install

接下来,运行以下命令来设置您的本地 Discourse 实例:

bundle exec rake db:create
bundle exec rake db:migrate
RAILS_ENV=test bundle exec rake db:create db:migrate

启动 Rails 和 Ember 服务器,您有两种选择。

选项 1:使用两个独立的终端标签页/窗口,分别通过以下命令运行 Rails 和 Ember CLI:

bundle exec rails server

bin/ember-cli

选项 2:仅使用一个终端标签页/窗口:

bin/ember-cli -u # 将在后台运行 Pitchfork 服务器

:tada: 现在您应该可以访问 http://localhost:4200 查看您的本地 Discourse 安装。(请注意,首次加载可能需要长达一分钟,因为服务器正在预热。)

您还可以尝试运行测试:

bundle exec rake autospec

所有(或几乎所有)测试都应通过。

创建新管理员

要创建新管理员,请运行以下命令:

RAILS_ENV=development bundle exec rake admin:create

按照提示创建管理员账户。

配置邮件

运行 MailHog:

mailhog

恭喜!您现在已成为自己 Discourse 安装的管理员!

愉快开发!要开始开发,请参阅 Discourse 插件创建入门指南


本文档已进行版本控制 - 如有修改建议,请在 GitHub 上提出。

78 个赞
Setup discourse on Mac OS
Running Discourse on Docker for Mac
Localhost:3000/users gives no-results
How to install Discourse on windows
How to install Discourse locally?
Best dev installation method for running on macOS?
Please help, how do I install Discourse on macOS?
Local installation internal use only
Help me setup my Discourse development environment
Discourse standalone
Migrate a NodeBB forum with Redis to Discourse
Starting discourse fails with bootstrap error
Error after cleaning tmp folder
MacOS Installation Gem::FilePermissionError
UndefinedTable: ERROR: relation "web_hook_event_types" when trying to run rspec test
[Need help][MacOS M1 dev installation] ArgumentError unknown keywords
Migrate a PunBB forum to Discourse
Migrate a phpBB3 forum to Discourse
Migrate a FluxBB forum to Discourse
Migrate a vBulletin 3 forum to Discourse via XenForo
Regarding the installation - docker
Migrate a NodeBB forum with MongoDB to Discourse
Migrate a Ning forum to Discourse
Migrate a Phorum forum to Discourse
Migrate from another forum to Discourse
Migrate a Kunena 3 forum to Discourse
Migrate a bbPress WordPress plugin forum to Discourse
Install Discourse for development using Docker
Use the Discourse API ruby gem
Enable CORS on localhost for DiscourseConnect
Set Environmental Variables
Need help integrating code wrote on Edittext to the Discourse
Keyboard navigation messes up the search menu
WP-Discourse not connected and admin email not recognized
Contributing to Discourse development
How to install discussions on localhost in my mac?
How to install Discourse for Wordpress locally running on MAMP
Error when building: "Runtime Error: discourse does not support compiling scss/sass files via sprockets"
Discourse as Your First Rails App
Migrate from GetSatisfaction to Discourse
Upgrading Mathjax to version 4
Windows server publish method
Migrate a MyBB forum to Discourse
Category option: max topics per user (2 use-case examples)
Can't deploy to heroku
[PAID] Import from Legacy Postgres DB
Vagrant based server failing on db:migrate
Change unicorn port from 3000 in development
I want to build a debug version of discourse
Moderation Tools
Rails server --daemon and plugins
Installing problem - bundle install
Nginx Performance Report plugin incompatible with development environment setup script
Rake aborted message is showing when installing vagrant development
Update PhantomJS to latest for Ubuntu dev guide?
Cannot Backup my Development Instance (Fails)
Install error : Protocol violation
Can't set up dev environment due to cppjieba_rb failing to install
How to edit the discourse files? A development box?
How to add a new language
How to relax Content Security Policy
Installing Discourse for macOS Development Using asdf and docker-compose
Override profile background via SSO
Can't set up dev environment due to cppjieba_rb failing to install
Stuck in infinite loop in Mac terminal after source ~/.bashrc
Install on macOS – Failure: Scheduler::Defer can pause and resume
Disabling SSO in development environment
Local development and deploying from same repo
Discourse Connect on Local instance is not working
Can't start localhost server -- file was built for x86_64 which is not the architecture being linked (i386)
Please help, how do I install Discourse on macOS?
How to connect to an external database running on localhost
How can I include discourse in my local dev stack?
Topic List Previews (TLP)
Global messages on 94632 timed out, restarting process, 95535 successfully terminated by `TERM` signal
Cannot get embedding to work
/admin/config/emoji non responsive/locks up
App.yml file does not exist when installing Discourse locally
Ember-cli error on local MacOS development
Importing / migrating from Zendesk Community to Discourse
Redis version error when I run bundle exec db:create
Dev environment setup failed on bundle install
Set up a local Discourse Development Environment?

If anyone is getting failing specs with most of them being .count errors, then try the following:

RAILS_ENV=test bundle exec rake db:reset

I had a problem where development data somehow got into my test database and was causing lots of failures.

7 个赞

Is it possible to reset a discourse completely?

2 个赞

Yes, do:

rake db:drop db:create db:migrate

Note that this will wipe everything and you will have to create your Admin user account again.

11 个赞

Can someone assist me in how I can update my discourse?

/launcher rebuild app

returns an error.

1 个赞

./launcher rebuild app is for discourse_docker based production setup. To update local/development Discourse instance you need:

cd ~/discourse
git pull origin master
8 个赞

I get this error @techAPJ,

error: Your local changes to the following files would be overwritten by merge:
	.gitignore
Please commit your changes or stash them before you merge.
Aborting

The error message is pretty clear:

Please commit your changes or stash them before you merge.

If you want to ignore your local changes, do:

git fetch origin
git reset --hard origin/master
7 个赞

根据 Ruby on Rails 论坛的指南,我目前卡在步骤 7。

这可能是一个非常“新手”的问题,但我该如何“指向”该主题中链接的实验性分支呢?我尝试了几种方法,但每次都会收到 Unknown command mini_racer 的错误提示。

1 个赞

他们在这里提问没问题。

我们在本指南中引用了 我们撰写的特定 M1 说明,并在 Rails 论坛上进行了讨论。

我稍后需要在我的 M1 Air 上查看,也许最近刚设置新 Mac 的同事会更清楚这是否仍有必要。不过,在第 7 步中有一个如何指向分支的示例:

gem 'mini_racer', github: 'rubyjs/mini_racer', branch: 'refs/pull/186/head'

因此,您需要编辑本地版本 discourse/Gemfile 中的这一行:

然后运行 bundle install

4 个赞

它就在原始帖子的顶部链接着。

Ruby on Rails 论坛的那个话题已经沉寂好几个月了。原帖作者(OP)自二月以来就不活跃了,也没有回复那里任何寻求帮助评论。

这里有更多能帮我的人。我只是说说。:wink:

我尝试将其复制到终端,但收到了和之前一样的 Unknown command mini_racer 错误。

诚实地说,Ruby on Rails 论坛的指南在这方面确实不如我希望的清晰。

提前致歉……:pray:

2 个赞

这不是一个要运行的命令。您需要编辑位于 discourse 目录内的实际文本文件 “Gemfile”。

1 个赞

哎呀!:facepalm:

谢谢!我现在就试试。

在我看来,有人应该编辑 Ruby on Rails 论坛中的指南,并对第 7 步提供更进一步的说明。这只是我的一点个人意见。

我马上回来。请稍等……

1 个赞

抱歉我得先走了,但我认为针对 M1 Mac 的 mini_racer 修复已经合并了。我刚刚检查了 M1 Mac 上的 Gemfile,我的并没有被修改。所以我认为你可以跳过第 7 步。

3 个赞

我执行了步骤 8,但收到了“无法找到 Gemfile”的错误。

我(认为)已经解决了步骤 7,但步骤 8 仍然给我带来麻烦,并输出了上述错误。

运行 bundle install 时,您需要位于 discourse 目录下。

@merefield:您能多描述一下您的远程设置吗?

虽然开发主题允许我在实时网站上添加更改,但对于开发插件,我似乎别无选择,只能在我本地机器上进行,将整个 discourse 代码库放在那里(并在其之上放置我的插件)。

结果是,对于编码插件时的任何(非 CSS)更改,当我重新加载它时,1) 会启动我电脑的风扇,2) 需要整整 30 秒才能重新加载。如果我需要重启服务器,则需要几分钟。

这些延迟确实会累加——结果是我可能需要一个小时才能编写完一些东西,而按照我正常的编码流程(有热重载或每次更改最多 2-3 秒)只需要15 分钟

所以,我很想听听任何加快速度的建议。

1 个赞

这或许更适合放在 Ubuntu 主题 上,因为我只是在云服务器上运行该安装,前面有 nginx 和完整的 DNS(无 docker),所以我实际上是在处理域名。一切都从终端运行。我甚至已经让 Ember CLI 在该设置中运行良好。

它也不是很快,但足够快。它的好处是可以运行和测试完整的 https 回调服务。

据我所知,目前最快的插件开发环境是本地的 Docker Dev on WSL2,它运行速度极快。它也非常容易维护。不幸的是,据我所知 discourse_theme 在该环境中还不能正常工作,所以我又回到了我的云服务器上进行这项工作。

苹果在这方面落后真是有点奇怪?微软的工程师们已经证明了他们非常精明。

3 个赞

如果有人在安装 ruby 2.7.3 时遇到错误,显然 Xcode 12 之后的一些更改破坏了 rbenv 的安装过程:

尽管我已安装最新版本的 psych 和 libyaml,但仍收到此错误:

似乎您的 ruby 安装缺少 psych(用于 YAML 输出)。
要消除此警告,请安装 libyaml 并重新安装您的 ruby。

我尝试了指南中建议的解决方法,但仍然收到相同的错误,最后不得不使用 rvm:

rvm install 2.7.3
1 个赞

关于如何更快地进行插件编程,我最近改变了我的方法。而且效果很好。基本上,将任何前端的东西移到一个主题组件中,只在插件本身中编写后端的东西。我知道其他人以前也发现了这一点。但现在我这样做了,编程速度更快,体验也更好。详情请参见此处

3 个赞