Install Discourse on Windows for development

Discourse
Fri, 01 Dec 2017 06:36:51 +0000
Developer Guides

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.

Install Discourse on Ubuntu or Debian for Development

Install Discourse Dependencies

You will need the following packages on your system:

Git

rbenv or asdf

ruby-build

Ruby (latest stable)

Rails

PostgreSQL

SQLite

Redis

Node.js

pnpm

MailHog**

ImageMagick**

** optional

Now that we have installed Discourse dependencies, let’s move on to install Discourse itself.

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

3. Then go through all the remaining steps of the Ubuntu guide.

Install Discourse on Ubuntu or Debian for Development

Clone Discourse

Clone the Discourse repository in ~/discourse folder:

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

~ indicates home folder, so Discourse source code will be available in your home folder.

Setup Database

Create role with the same name as your ubuntu system username:

sudo -u postgres createuser -s "$USER"

Bootstrap Discourse

Switch to your Discourse folder:

cd ~/discourse

Install the needed gems

source ~/.bashrc
bundle install

Now that you have successfully installed gems, run these commands:

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

Try running the specs:

bundle exec rake autospec

All the tests should pass.

Start rails server:

bundle exec rails server

You should now be able to connect with your Discourse app on http://localhost:3000 - try it out!

Starting with Discourse 2.5+ EmberCLI is required in development and these additional steps will be required:

In a separate terminal instance, navigate to your discourse folder (cd ~/discourse) and run:

bin/ember-cli

You should now be able to navigate to http://localhost:4200 to see your local Discourse installation.

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

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

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: (clicca per ulteriori dettagli) As of July 1, 2020 (clicca per ulteriori dettagli)

Last Reviewed by @SaraDev on Thursday, June 16, 2022 2:00 AM UTC

This document is version controlled - suggest changes on github.

15 messaggi - 10 partecipanti