Guide to Setting Up Discourse Development Environment - Windows 11

AliBenBongo
Sat, 14 Oct 2023 10:38:25 +0000
Self-hosting

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

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

wsl.exe --update

2. Install Ubuntu on WSL2 using this command:-

wsl.exe --install -d Ubuntu

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

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

sudo apt update && sudo apt upgrade -y

5. Now that everything is updated we can proceed

WSL Modifications

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

sudo nano /etc/wsl.conf

7. 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"

8. Completely close the WSL terminal and relaunch it for these changes to properly apply.

9. 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)

10. Start the PostgreSQL service:-

sudo service postgresql start

11. 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

12. Run the following so that the redis-server automatically restarts:-

redis-server --daemonize yes

13. Clone Discourse into the home folder:-

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

14. Change to the newly-created Discourse folder:-

cd ~/discourse

15. 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

16. Setup the environment:-

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

17. Start Discourse

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

18. 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.

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

20 messaggi - 14 partecipanti