Install Discourse on Windows 10 for development

:information_source: This tutorial has been tested on Windows 10 and 11.
So you want to set up a development environment for Discourse on Windows 10 (or windows 11)? You can do it easily using Windows Subsystem for Linux feature. It is faster too :star_struck:.

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

50 Likes

Alright, found a solution.

I noticed that replacing 127.0.0.1 with localhost would fix the images.

After searching a bit, this the command you can use to start Discourse:

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


I will try to update the guide later.

4 Likes

Any chance to review this PR?

That would make this guide a little friendlier.

3 Likes

Any idea why I’m getting β€œUnfortunately, an unexpected error occurred, and Bundler cannot continue.” After bundle install ?

1 Like

same problem

Can you supply a screenshot of the error. What version of Ruby do you have installed?

I’m having trouble of dependencies:

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$

How can I get it fixed easily? I was trying to install 2.6.0, then 2.7.0, but there are always other troubles with this.

As per some of the earlier comments, I also ran into some difficulties and errors while trying to follow this guide - tried on both a Windows 10 and Windows 11 desktop.

After some trial-and-error I finally have steps that result in a fully working development environment under Windows 11, tested on the latest 22H2 build and also on the upcoming 23H2 Release Preview (I assume it will also work on the newest build of Windows 10)

If it’s of use to anybody, I have just posted the guide here:-

Hopefully this helps people like myself who are trying to get Discourse running under Windows :smiley:

2 Likes

I went through this whole official guide again to ensure nothing broke since my last try.
I installed Ubuntu (unspecified version) via WSL on Windows 11, which installed the last LTS version, 22.04 in this case.

I didn’t encounter any issues; all straightforward, no errors, and the dev installation works.

If you have trouble installing something using one of our official guides in the future, please write down the errors and report them to us, it’s always useful :smile:


Two warnings though:

When installing Node.js:

================================================================================
β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“
================================================================================

                           SCRIPT DEPRECATION WARNING


  This script, located at https://deb.nodesource.com/setup_X, used to
  install Node.js is deprecated now and will eventually be made inactive.

  Please visit the NodeSource distributions Github and follow the
  instructions to migrate your repo.
  https://github.com/nodesource/distributions

  The NodeSource Node.js Linux distributions GitHub repository contains
  information about which versions of Node.js and which Linux distributions
  are supported and how to install it.
  https://github.com/nodesource/distributions


                          SCRIPT DEPRECATION WARNING

================================================================================
β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“β–“
================================================================================

TO AVOID THIS WAIT MIGRATE THE SCRIPT
Continuing in 60 seconds (press Ctrl-C to abort) ...

When running redis-server --daemonize yes:

# WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

Unsure why I had so many issues then! Perhaps there was something strange in my Windows install that I managed to fix during my troubleshooting without realising it! :stuck_out_tongue:

Still, I’m still happy with what I’ve learnt so far and look forward to continuing to work with migrating my forums across to Discourse.

2 Likes

I had to reinstall Windows, and I have now a fresh Windows 11 installed.
I will follow the guide and report back later! Will keep @AliBenBongo’s guide in mind as well.

1 Like

Here is a follow-up.

The guide could surely use an update, but it still works wonderfully well on a fresh Windows 11 22H2. :+1:

The only issue I had, was even though wsl command was working in a terminal, the WSL feature was actually not enabled by default:

image

3 Likes