Guide to Setting Up Discourse Development Environment - Windows 11

Hi Everyone,

After spending some time attempting to get a working development environment up and running under Windows 11 / WSL2 I thought I would share the steps that I have followed.

This is my first post here so I hope that this is of use to somebody :slight_smile: I am a Systems Administrator used to working with Windows so this has been an interesting journey learning Linux / Ruby / Discourse etc.

A few things seem to have changed since the guide for Windows 10 was written and I ran into a few issues along the way (and from reading the comments, I wasn’t the only one!)

I can confirm that the following instructions worked on my Windows 11 Pro 22H2 install & also on my Windows Insider build of the upcoming Windows 11 23H2 Release Preview.

I’ll try to keep the instructions as short and straightforward as possible :slight_smile:

Initial Preparation

  1. Check for any WSL updates and install them if applicable. From a Windows Powershell window use this command:-

wsl.exe --update

  1. Install Ubuntu on WSL2 using this command:-

wsl.exe --install -d Ubuntu

  1. Follow the onscreen prompts to create the username and password

  2. Once you’re in the Ubuntu terminal, check for and install all applicable updates

sudo apt update && sudo apt upgrade -y

  1. Now that everything is updated we can proceed :slight_smile:

WSL Modifications

  1. Before cloning Discourse, run the following command to open the /etc/wsl.conf file:-

sudo nano /etc/wsl.conf

  1. At the bottom of the existing file, add the following , press Ctrl + X to save the changes and press “Y” when prompted.
[automount]
enabled  = true
root     = /mnt/
options  = "metadata,umask=22,fmask=11"
  1. Completely close the WSL terminal and relaunch it for these changes to properly apply.

  2. Now copy and paste the following one-line installation script to set up the development environment. Depending on the speed of your computer and/or internet connection this might take a bit of time to complete, so go and grab a coffee or something!

bash <(wget -qO- https://raw.githubusercontent.com/discourse/install-rails/master/linux)

  1. Start the PostgreSQL service:-
sudo service postgresql start

  1. Because we’re running in WSL2 I got a warning message about the VM running out of memory, which can be solved by running the following
sudo sysctl vm.overcommit_memory=1

  1. Run the following so that the redis-server automatically restarts:-
redis-server --daemonize yes
  1. Clone Discourse into the home folder:-
git clone https://github.com/discourse/discourse.git ~/discourse

  1. Change to the newly-created Discourse folder:-
cd ~/discourse

  1. Run the following commands (I did them one line at a time)(Unsure whether this is necessary or if they can be copied and pasted in one go)
source ~/.bashrc

bundle install

yarn install

  1. Setup the environment:-
RAILS_ENV=development bundle exec rake db:create db:migrate

  1. Start Discourse
DISCOURSE_HOSTNAME=localhost UNICORN_LISTENER=localhost:3000 bin/ember-cli -u

  1. Open a separate terminal , change into the Discourse directory using cd ~/discourse and run rails admin:create - follow the instructions to set up your Admin user account.

  2. Go to http://localhost:4200 in a web browser and Discourse should all be up and running :slight_smile:

9 Likes

This part might fail. If it does click start , type turn windows features on or off
Enable virtual machine platform
Reboot

Resume the commands.

2 Likes

Thanks for adding this Andrew!

One very important thing that I struggled with for a while to figure out is that the repo absolutely must be on the WSL filesystem (i.e., NOT on /mnt/*). Otherwise, you’ll either get all kinds of odd errors or have a very, very, very slow instance.

This is supposed to be common knowledge, but from my interaction with other devs, it kind of isn’t.

2 Likes

Hi AliBenBongo :wave:

Thank you for this guide.

Out of curiosity, did you try Install Discourse on Windows 10 for development but faced issues on Windows 11?

I followed this official guide less than two months ago to set up my dev install on Win11, and it worked flawlessly.

2 Likes

That’s interesting yes I did try that guide first and ran into many error messages. I can’t remember specifically but some of the error messages were mentioned in the comments section of that same thread …

Think this is a good thing in the end as I’ve definitely got more knowledge now through resolving the issue myself and then writing this guide up! :slight_smile:

1 Like

Probs a dum question but I have to ask. Assuming I could get this up and running following your guide. Do you think it’s possible to reverse proxy this to a domain?

There are no dumb questions, we can all always learn something new! :slight_smile: I don’t have much experience with reverse proxy stuff except for using Nginx Proxy Manager in a Docker container - perhaps have a look at that as it does most of the hard work and even generates free SSL certificates through Let’s Encrypt

1 Like

You are going to hit a lot of pain points I suspect. The dev install is not supported to run in Production.

Running the standard install in the cloud might cost a few dollars a month but how much is your time worth?! With that you can be up and running in 30 minutes and be done.

2 Likes

That is in fact what I have done. I started off with on communiteq, I also tried DigitalOcean but have ultimately landed on Contabo.

I think I might be a lunatic because what I was trying doing (just to see if I could), running Ubuntu in HyperV, I even managed to get the VM on the same subnet lol but I could not get initial domain check to work. I think part of the problem is that I am already hosting a handfull of services on my Windows host and consequently I am port forwarding 80/443 to that machine IP. I know it’s beyond the scope of this thread and it’s not supported, but have you any experience trying to do something similar?

It should be noted that, if you don’t have any subsystems installed yet then this command will not work.

1 Like

I got stuck on installing Ruby; this helped me: https://chatgpt.com/share/34bf1295-7f31-450d-90cc-d850c113bc2b

Hi, welcome :wave:

If you follow the steps in this guide, you won’t need to install Ruby manually. The “install-rails” script will do that automatically.