macOS Catalina Discourse Development Environment Notes

Notes for Discourse Development on macOS Catalina

Ruby Gems & Catalina

macOS Catalina runs on a dedicated, read-only system volume and so we cannot install various Ruby binaries in the /usr/bin directory. One good solution to this is to change your environmental variables as follows (using your own home directory, of course):

export GEM_HOME=/Users/Tim/bin
export GEM_PATH=/Users/Tim/bin

You also need to make sure you are running rbenv so it is a good idea to run this before running bundle install

rbenv init
export PATH=~/.rbenv/shims:$PATH

This should solve most of the problems with Ruby gems for Discourse on macOS, and you should be able to run bundle install.

However, this often fails regarding cppjieba_rb so you might need to manually install cppjieba_rb.

See Also NoBugsBunny post #15 here:

Gem Documents

You might save yourself a lot of time by instructing gem not to download any gem docs:

You just add the following line to your local ~/.gemrc file before installing gems manually or running bundle install.

gem: --no-document

If that does not work for any reason, you can append --no-document to any gem instruction, like so:

 gem install <gemname> --no-document

Real world example:

gem install cppjieba_rb -v '0.3.3' --source 'https://rubygems.org/ --no-document'

After you get all your gems figured out and discourse is installed, you may need to manually start unicorn and the rails server:

bundle exec rails server
bundle exec unicorn

It is good to run both of the commands in two different terminal windows so you can see what is going on all the time with unicorn and rails.

I recommend you append this to your shell start resource file, something like this in your .bashrc file (quick example only):

$ cat /Users/Tim/.bashrc
export GEM_HOME=/Users/Tim/bin
export GEM_PATH=/Users/Tim/bin
export RAILS_ENV=development
# load rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - --no-rehash)"

Reference Document:

If you have any issues, please let me know as I am currently fully setup on macOS Catalina for Discourse plugin development. In fact, I used the macOS dev setup to fix a bug in my first Discourse plugin this morning:

3 Likes

For those interested in Discourse plugin development on macOS.....

How do I fire up my Discourse development environment in the morning?

First:

cd /var/discourse

Then run this in one terminal window in the same directory:

export GEM_HOME=/Users/Tim/bin
export GEM_PATH=/Users/Tim/bin
export RAILS_ENV=development
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - --no-rehash)"
bundle exec rails server

and run this in another terminal window in the same directory::

export GEM_HOME=/Users/Tim/bin
export GEM_PATH=/Users/Tim/bin
export RAILS_ENV=development
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - --no-rehash)"
bundle exec unicorn

and finally, for coding, running Visual Studio Code (VSC) for coding:

code .

and for committing plugins to git:

cd plugins
cd my-current-working-plugin
git add .
git commit -m "UPDATE: Adding code"
git push

That's it in a nutshell.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

Note, that this command above does not work now, so forgot "no-document" and just do:

gem install cppjieba_rb -v '0.3.3' --source 'https://rubygems.org/'

Just a macOS dev note, based on a bunch of Rails development projects running currently on macOS lately:

Because of the various roadblocks and system security issues regarding macOS Catalina and above, I have found it best to bundle Rails app like this:

bundle install --path vendor/bundle

Since I started bundle’ing with the path switch above, getting all my Rails development apps up and running on macOS has been much easier.