# Mooie manier om een dev-omgeving te draaien

**URL:** https://meta.discourse.org/t/nice-way-to-run-a-dev-env/375233
**Category:** Extras
**Tags:** dev-install, development
**Created:** [22 juli 2025 om 13:01 UTC](https://meta.discourse.org/t/nice-way-to-run-a-dev-env/375233 "2025-07-22T13:01:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [22 juli 2025 om 13:01 UTC](https://meta.discourse.org/t/nice-way-to-run-a-dev-env/375233/1 "2025-07-22T13:01:36Z")

</div>

Hi everyone, just sharing a handy script I’ve put together that helps me run my Discourse dev instance.

It pulls all the latest changes, pulls the updates from installed plugins, and runs all the migrations, as well as installing the necessary gems and pnpm packages.

The downside to the script is that it also pulls the plugins bundled with core, which technically wouldn’t do anything since they would be updated with the first `git pull`. Oh well.

Note: [chatgpt.com](http://chatgpt.com) helped me write the `if` statement logic (my initial experiments failed).  
`~/rundiscourse.sh`:

```bash
#!/bin/bash

cd ~/discourse
git pull
cd plugins
PLUGIN_DIR=~/discourse/plugins

for folder in "$PLUGIN_DIR"/*; do
  if [-d "$folder/.git"]; then
    output=$(git -C "$folder" pull)
    if ! echo "$output" | grep -q "Already up to date."; then
      echo "[$(basename "$folder")] $output"
    fi
  fi
done
cd ~/discourse
bundle install
pnpm install
bin/rails db:migrate
DISCOURSE_HOSTNAME=localhost UNICORN_LISTENER=localhost:3000 bin/ember-cli -u

```

Then, run:

```bash
chmod +x rundiscourse.sh

```

Then, go to the `~/.bashrc` file (using `nano`, or anything), and add this bit if you don’t already have it (it’s nearer the bottom)

```bash
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [-f ~/.bash_aliases]; then
    . ~/.bash_aliases
fi

```

Then, add the following to the `~/.bash_aliases` file:

```bash
alias discourse="~/rundiscourse.sh"

```

Close your terminal and re-open it.  
Now, when you run `discourse` in the terminal, your development environment should start!

* * *

I hoped this helped! Also, do let me know if I’m doing something wrong, or if it can be improved. Thanks!

---

<div class="post-metadata">

### Author: ![elmuerte](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elmuerte/32/456517_2.png) [@elmuerte](https://meta.discourse.org/u/elmuerte)
#### Post date: [22 juli 2025 om 18:31 UTC](https://meta.discourse.org/t/nice-way-to-run-a-dev-env/375233/2 "2025-07-22T18:31:50Z")

</div>

Nice. Een paar suggesties.

De shebang moet `#!/usr/bin/env sh` zijn, wat het meest draagbaar is. Het script gebruikt geen bash-specifieke commando’s, dus het zou moeten werken in elke Bourne shell-compatibele shell, niet alleen bash.

Voeg na de shebang `set -e` toe. Dit zorgt ervoor dat het script stopt als een van de commando’s mislukt. Anders zal het vrolijk doorgaan met het uitvoeren van commando’s en later falen omdat iets als `bundle install` is mislukt, en de foutmelding is nu verdwenen van het scherm van de gebruiker.

Nu is de plugin git pull een beetje problematischer, omdat fouten die naar STDERR worden geschreven en een falende git-uitvoering niet correct zullen worden afgehandeld. Dus ik heb STDERR ook naar STDOUT gepusht en de exit code bijgehouden.

Geen noodzaak voor een reeks `cd` commando’s, of het instellen van de `PLUGIN_DIR` variabele.

```sh
#!/usr/bin/env sh
set -e

cd ~/discourse
git pull

for folder in plugins/*; do
  if [-d "$folder/.git"]; then
    exitcode=0
    output=$(git -C "$folder" pull 2>&1) || exitcode=$?
    if echo "$output" | grep -q -v "Already up to date."; then
      echo "[$(basename "$folder")]"
      echo "$output"
      ["$exitcode" -ne 0] && exit "$exitcode"
    fi
  fi
done

bundle install
pnpm install
bin/rails db:migrate
DISCOURSE_HOSTNAME=localhost UNICORN_LISTENER=localhost:3000 bin/ember-cli -u

```

Ik had al een vergelijkbaar script, behalve de git pulling, omdat ik niet wil dat dat elke keer gebeurt.

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [22 juli 2025 om 22:49 UTC](https://meta.discourse.org/t/nice-way-to-run-a-dev-env/375233/3 "2025-07-22T22:49:45Z")

</div>

Bedankt voor het inzicht! Ik zal dat proberen.
