Instala Discourse en macOS para desarrollo

:warning: This guide covers installation instructions for a macOS development environment, for production guides see: Install Discourse in production with the official supported instructions

So you want to set up Discourse on macOS to hack on and develop with?

We’ll assume that you don’t have Ruby/Rails/Postgres/Redis installed on your Mac. Let’s begin :rocket: !

Install Discourse Dependencies

You will need the following packages on your system:

** optional

restart your terminal

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

Restart your Terminal

Exit your shell and restarting it ensures that the paths to the installed packages are correctly picked up by the Terminal.

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.

Bootstrap Discourse

Switch to your Discourse folder:

cd ~/discourse

Install the needed gems

bundle install

Install the JS dependencies

pnpm install

Next, run these commands to set up your local Discourse instance:

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

Start rails + Ember servers, you have two options here.

Option 1: using two separate Terminal tabs/windows, run Rails and Ember CLI separately via

bundle exec rails server

and

bin/ember-cli

Option 2: using only one Terminal tab/window:

bin/ember-cli -u # will run the Unicorn server in the background

:tada: You should now be able to navigate to http://localhost:4200 to see your local Discourse installation. (Note that the first load can take up to a minute as the server is warmed up.)

You can also try running the specs:

bundle exec rake autospec

All (or almost all) the tests should pass.

Create New Admin

To create a new admin, run the following command:

RAILS_ENV=development bundle exec rake admin:create

Follow the prompts to create an admin account.

Configure Mail

Run MailHog:

mailhog

Congratulations! You are now the admin of your own Discourse installation!

Happy hacking! And to get started with that, see Beginner’s Guide to Creating Discourse Plugins.


This document is version controlled - suggest changes on github.

77 Me gusta

If anyone is getting failing specs with most of them being .count errors, then try the following:

RAILS_ENV=test bundle exec rake db:reset

I had a problem where development data somehow got into my test database and was causing lots of failures.

7 Me gusta

Is it possible to reset a discourse completely?

2 Me gusta

Yes, do:

rake db:drop db:create db:migrate

Note that this will wipe everything and you will have to create your Admin user account again.

11 Me gusta

Can someone assist me in how I can update my discourse?

/launcher rebuild app

returns an error.

1 me gusta

./launcher rebuild app is for discourse_docker based production setup. To update local/development Discourse instance you need:

cd ~/discourse
git pull origin master
8 Me gusta

I get this error @techAPJ,

error: Your local changes to the following files would be overwritten by merge:
	.gitignore
Please commit your changes or stash them before you merge.
Aborting

The error message is pretty clear:

Please commit your changes or stash them before you merge.

If you want to ignore your local changes, do:

git fetch origin
git reset --hard origin/master
7 Me gusta

Using the guide from the Ruby on Rails forum, I’m currently stuck on step 7.

This is probably a very “newbie” question, but how do I “point” to the experimental branch that was linked in that topic? I tried a few things and was ultimately giving the Unknown command mini_racer, message every single time.

1 me gusta

They’re fine asking here.

There are some specific m1 instructions we wrote that we reference on the rails forum in this guide.

I’d have to look on my m1 air later, and maybe my fellow coworks who recently setup new macs might know better if this is even still needed, but there is an example of how to point to a branch in step 7:

gem 'mini_racer', github: 'rubyjs/mini_racer', branch: 'refs/pull/186/head'

So you would edit this line in your local version of discourse/Gemfile:

and then run bundle install.

4 Me gusta

It’s linked right at the top of the original post.

The topic from the Ruby on Rails forum has been dead for many months now. The OP hasn’t been active since Feburary and hasn’t replied to any comments there asking for help.

There are more people to help me here. Just saying. :wink:

I tried copying that into Terminal and received the same Unknown command mini_racer, error from before.

Admittedly, the guide from the Ruby on Rails forum isn’t as clear as I’d hope in that regard.

Apologies in advance… :pray:

2 Me gusta

It’s not a command to run. You will need to EDIT the actual text file called “Gemfile” located inside the discourse directory.

1 me gusta

Doh! :facepalm:

Thanks! Let me try that right now.

In my opinion, somebody should edit the guide from the Ruby on Rails forum and provide further clarification regarding step 7. Just my two cents though.

I will be right back. Hold on a second…

1 me gusta

Sorry I have to run, but I think that mini_racer fix for m1 macs has been merged in. I just checked my Gemfile on my m1 mac and mine isn’t edited. So I think you can skip step 7.

3 Me gusta

I ran step 8 and received the Could not locate Gemfile error.

I (think) I was able to figure out step 7, but step 8 is still giving me trouble and is spitting out the error mentioned above.

You need to be inside of the discourse directory when you run bundle install.

Hola @merefield: ¿Puedes describir un poco más tu configuración remota?

Si bien desarrollar un tema me permite aplicar cambios en un sitio en vivo, para desarrollar un plugin no veo otra forma que hacerlo en mi máquina local, teniendo todo el código base de Discourse allí (con mi plugin encima).

El resultado es que para cualquier cambio (que no sea de CSS) al codificar un plugin, cuando lo recargo 1) se encienden los ventiladores de mi computadora y 2) tarda unos sólidos 30 segundos en recargarse. Y si necesito reiniciar el servidor, tarda varios minutos.

Esos retrasos se acumulan, con el resultado de que podría tardar una hora en codificar algo que, con mi flujo de codificación normal (donde hay recarga en caliente o como máximo 2-3 segundos por cambio), tardaría 15 minutos.

Por lo tanto, agradecería cualquier sugerencia para acelerar las cosas.

1 me gusta

Esto, argumentablemente, estaría mejor en el tema de Ubuntu, ya que solo estoy ejecutando esa instalación en un servidor en la nube, con nginx y un DNS completo (sin docker), por lo que en realidad estoy abordando el dominio. Ejecutando todo desde la terminal. Incluso he conseguido que Ember CLI funcione bien en esa configuración ahora.

Tampoco es tan rápido, pero lo suficientemente rápido. Tiene el beneficio de poder ejecutar y probar servicios completos de devolución de llamadas https.

El entorno de desarrollo de plugins más rápido con el que estoy familiarizado es Docker Dev en WSL2, que funciona a la perfección. También es extremadamente fácil de mantener. Desafortunadamente, discourse_theme aún no funciona en ese entorno, hasta donde sé, así que he vuelto a mi servidor en la nube para ese trabajo.

Es un poco extraño por qué Apple se está quedando atrás aquí. Los ingenieros de Microsoft han demostrado ser muy astutos.

3 Me gusta

En caso de que alguien reciba errores al intentar instalar ruby 2.7.3, aparentemente algo cambió después de Xcode 12 que rompe el proceso de instalación con rbenv:

Seguí recibiendo esto, a pesar de tener las últimas versiones de psych y libyaml instaladas:

Parece que a tu instalación de ruby le falta psych (para la salida YAML).
Para eliminar esta advertencia, por favor instala libyaml y reinstala tu ruby.

Intenté la solución alternativa que sugieren en la guía, pero seguí recibiendo el mismo error y terminé teniendo que usar rvm:

rvm install 2.7.3
1 me gusta

En cuanto a cómo programar más rápido al crear un plugin, recientemente he cambiado mi enfoque. Y está funcionando muy bien. Básicamente, mueve todo el contenido del frontend a un componente temático y solo codifica las cosas del backend en el propio plugin. Sé que otros ya lo han descubierto antes. Pero ahora que lo estoy haciendo, la programación es mucho más rápida y agradable. Detalles aquí.

3 Me gusta