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 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
Initial Preparation
- Check for any WSL updates and install them if applicable. From a Windows Powershell window use this command:-
wsl.exe --update
- Install Ubuntu on WSL2 using this command:-
wsl.exe --install -d Ubuntu
-
Follow the onscreen prompts to create the username and password
-
Once youâre in the Ubuntu terminal, check for and install all applicable updates
sudo apt update && sudo apt upgrade -y
- Now that everything is updated we can proceed
WSL Modifications
- Before cloning Discourse, run the following command to open the /etc/wsl.conf file:-
sudo nano /etc/wsl.conf
- 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"
-
Completely close the WSL terminal and relaunch it for these changes to properly apply.
-
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)
- Start the PostgreSQL service:-
sudo service postgresql start
- 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
- Run the following so that the redis-server automatically restarts:-
redis-server --daemonize yes
- Clone Discourse into the home folder:-
git clone https://github.com/discourse/discourse.git ~/discourse
- Change to the newly-created Discourse folder:-
cd ~/discourse
- 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
- Setup the environment:-
RAILS_ENV=development bundle exec rake db:create db:migrate
- Start Discourse
DISCOURSE_HOSTNAME=localhost UNICORN_LISTENER=localhost:3000 bin/ember-cli -u
-
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.
-
Go to http://localhost:4200 in a web browser and Discourse should all be up and running