在Windows上安装Discourse进行开发

:information_source: This tutorial has been tested on Windows 10 and 11.

To set up a development environment for Discourse on Windows, you can do it using Windows Subsystem for Linux feature.

This setup requires the WSL 2 installation. It is only available in Windows 10 builds 18917 or higher. We’ll assume that you already installed Windows Subsystem for Linux 2 (Ubuntu) on your Windows 10 system. WARNING: Install Ubuntu 18.04, and not 20.04 since some installations will fail on 20.04. For more information see June 30th, 2020 notes at the bottom of this post.

Let’s begin!

Installing Discourse

  1. Initially follow the steps from the topic Beginners Guide to Install Discourse on Ubuntu for Development until the step Clone Discourse.
  1. Before setting up the database you have to start PostgreSQL service & Redis server manually using following commands

    sudo service postgresql start
    redis-server --daemonize yes
    
  2. Then go through all the remaining steps of the Ubuntu guide.

Creating a Command to Start Discourse

Now your development environment is almost ready. The only problem is every time when you open Ubuntu on Windows you have to start the PostgreSQL service & Redis server manually. Don’t worry we can have a workaround for this by creating a custom command :wink:

cd ~

Create a new file using the command nano start-discourse and paste the content below then save and exit.

#!/bin/bash

# to start PostgreSQL
sudo service postgresql start

# to start Redis server
redis-server --daemonize yes

Now modify the CHMOD using below command

chmod +x start-discourse

And copy the file to your bin folder

sudo cp start-discourse /usr/bin/

It’s done. Now, whenever you open the Ubuntu bash just run the command below and start developing :+1:

start-discourse

Alternatively, if you are using Windows 10 enterprise, pro, or education edition then you can create a Linux virtual machine in hyper-v to set up the Discourse dev environment.

Notes About Windows Environment

As of June 30, 2020:
As of July 1, 2020

Last Reviewed by @SaraDev on 2022-06-16T02:00:00Z


This document is version controlled - suggest changes on github.

52 个赞

好了,找到了一个解决方案。

我注意到将 127.0.0.1 替换为 localhost 可以解决图片问题。

搜索了一下,你可以使用以下命令来启动 Discourse:

DISCOURSE_HOSTNAME=localhost UNICORN_LISTENER=localhost:3000 bin/ember-cli -u


我稍后会尝试更新指南。

4 个赞

能帮忙看看这个 PR 吗?

这样能让这个指南更友好一些。

3 个赞

在运行 bundle install 后,为什么会出现“抱歉,发生意外错误,Bundler 无法继续。”的提示?

1 个赞

同样的问题

你能提供错误的截图吗?你安装的是什么版本的 Ruby?

我遇到了依赖项问题:

ux430uq@Asus-UX430UQ:~/discourse$ bundle install
You must use Bundler 2 or greater with this lockfile.
ux430uq@Asus-UX430UQ:~/discourse$ bundler -v
Bundler version 1.16.1

ux430uq@Asus-UX430UQ:~/discourse$ gem install bundler

Fetching: bundler-2.4.20.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/2.5.0 directory.
ux430uq@Asus-UX430UQ:~/discourse$
ux430uq@Asus-UX430UQ:~/discourse$ sudo gem install bundler
[sudo] password for ux430uq:
Fetching: bundler-2.4.20.gem (100%)
ERROR:  Error installing bundler:
        The last version of bundler (>= 0) to support your Ruby & RubyGems was 2.3.26. Try installing it with `gem install bundler -v 2.3.26`
        bundler requires Ruby version >= 2.6.0. The current ruby version is 2.5.0.
ux430uq@Asus-UX430UQ:~/discourse$ bundler -v
Bundler version 1.16.1
ux430uq@Asus-UX430UQ:~/discourse$

有什么简单的方法可以解决这个问题吗?我曾尝试安装 2.6.0,然后是 2.7.0,但总是遇到其他问题。

正如前面的一些评论所述,我在尝试遵循本指南时也遇到了一些困难和错误——在 Windows 10 和 Windows 11 桌面都进行了尝试。

经过一些反复试验,我终于找到了在 Windows 11 下成功搭建开发环境的步骤,并在最新的 22H2 版本和即将发布的 23H2 Release Preview 版本上进行了测试(我假设它也能在最新版本的 Windows 10 上运行)。

如果对大家有帮助,我刚刚在这里发布了指南:-

希望这能帮助到像我一样试图在 Windows 上运行 Discourse 的人们 :smiley:

2 个赞

我再次通读了整个官方指南,以确保在我上次尝试后没有任何东西损坏。
我在 Windows 11 上通过 WSL 安装了 Ubuntu(未指定版本),它安装了最新的 LTS 版本,即 22.04。

我没有遇到任何问题;一切都很顺利,没有错误,开发环境安装成功。

如果您将来在按照我们的官方指南安装某项内容时遇到麻烦,请记下错误并向我们报告,这总是有用的 :smile:


不过有两个警告:

安装 Node.js 时:

================================================================================
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
================================================================================

                           脚本弃用警告


  此脚本位于 https://deb.nodesource.com/setup_X,用于
  安装 Node.js 已弃用,并将最终失效。

  请访问 NodeSource distributions GitHub 并按照
  说明迁移您的仓库。
  https://github.com/nodesource/distributions

  NodeSource Node.js Linux distributions GitHub 存储库包含
  有关支持的 Node.js 版本和 Linux 发行版的信息
  以及如何安装。
  https://github.com/nodesource/distributions


                          脚本弃用警告

================================================================================
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
================================================================================

为避免此等待,请迁移脚本
将在 60 秒后继续(按 Ctrl-C 中止)...

运行 redis-server --daemonize yes 时:

# 警告:必须启用内存超额提交!否则,在内存不足的情况下,后台保存或复制可能会失败。禁用它也可能在内存未不足的情况下导致失败,请参阅 https://github.com/jemalloc/jemalloc/issues/1328。要解决此问题,请将 'vm.overcommit_memory = 1' 添加到 /etc/sysctl.conf,然后重新启动或运行命令 'sysctl vm.overcommit_memory=1' 使其生效。

我不确定当时我遇到这么多问题的原因!也许是我的 Windows 安装有问题,我在故障排除过程中无意中修复了它!:stuck_out_tongue:

不过,我仍然对到目前为止所学到的东西感到满意,并期待继续努力将我的论坛迁移到 Discourse。

2 个赞

我不得不重装了 Windows,现在我安装了一个全新的 Windows 11。
我将遵循指南,稍后汇报!我也会记住 @AliBenBongo 的指南。

1 个赞

这是一个后续跟进。

该指南肯定需要更新,但在全新的 Windows 11 22H2 上仍然运行得非常好。 :+1:

我遇到的唯一问题是,尽管 wsl 命令在终端中可用,但 WSL 功能实际上并未默认启用:

3 个赞

我认为本指南已过时。Ubuntu/Debian 指南中提到的步骤已不存在。

有什么方法可以撤销所有这些步骤,例如撤销软件包、gem 的安装脚本和克隆吗?

安装 18.04 覆盖 20.04 是否仍然是必需的?

安装 nodejs 时收到错误:

# apt install nodejs

Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 nodejs : Depends: libc6 (>= 2.28) but 2.27-3ubuntu1.6 is to be installed
E: Unable to correct problems, you have held broken packages.```