Beginners Guide to Install Discourse on macOS for Development

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

cd ~/discourse
git pull origin master
5 Likes

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
6 Likes

I got same error when I run bundle exec rspec

[Noah Dolph]:
3) Search include_diacritics allows strips correctly
Failure/Error: expect(results.posts.length).to eq(1)
expected: 1
got: 0
(compared using ==)
# ./spec/components/search_spec.rb:1071:in …
4) Search ignore_diacritics allows strips correctly
Failure/Error: expect(results.posts.length).to eq(1)
expected: 1
got: 0
(compared using ==)
# ./spec/components/search_spec.rb:1050:in …

and this was solved after set Postgres locale to C

I’m adding detail for someone who get this error.

When I check Postgres query result,

the result was different. so, rspec failed:

SELECT TO_TSVECTOR('simple', 'hello');
=> 'hello':1

SELECT TO_TSVECTOR('simple', 'สวัสดี');
=>

And locale was not set as C

]$psql -l
                                        List of databases
           Name           |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
--------------------------+----------+----------+-------------+-------------+-----------------------
 discourse_test           | hangu    | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 ...

Changed locale to C

When install and init Postgres by the Postgres.app,
I didn’t click init button. instead ran below command:

bin/initdb --locale=C -E UTF-8 -D ~/Library/Application\ Support/Postgres/var-11

and checked locale:

]$psql -l
                          List of databases
   Name    | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+---------+-------+-------------------
 postgres  | hangu | UTF8     | C       | C     |
 template0 | hangu | UTF8     | C       | C     | =c/hangu         +
           |       |          |         |       | hangu=CTc/hangu
 template1 | hangu | UTF8     | C       | C     | =c/hangu         +
           |       |          |         |       | hangu=CTc/hangu
(3 rows)

the query result:

SELECT TO_TSVECTOR('simple', 'hello');
=> 'hello':1

SELECT TO_TSVECTOR('simple', 'สวัสดี');
=> 'สวัสดี':1

and rspec passed.

I tried the solution you referenced:

> launchctl limit maxfiles
maxfiles    64000          524288 

But I’m still getting a bunch of urandom errors when I run the tests:

32) Report topic report with topics returns today's data
  Failure/Error: self.salt = SecureRandom.hex(16)

  RuntimeError:
    failed to get urandom
  # ./app/models/user.rb:1313:in `ensure_password_is_hashed'

I haven’t found any other clues on how to solve it or why it might be happening. Everything else seems to be working (I can access Discourse on localhost:3000).
For what it’s worth, I’m running Mojave 10.14.6 with Postgres 11.5 (from Homebrew)

I don’t think Postgres 11 is supported by Discourse. We plan to upgrade to 12 soon.

PG 11 should work fine for local dev, only big issue is if you need to take a database backup from dev and upload it to production.

This is this issue:

https://bugs.ruby-lang.org/issues/14716

Try:

cat /dev/urandom is that returning anything? If that is not working then you need to figure out how to sort that out on your mac.

5 Likes

Just a quick pointer, the Ruby install script linked at the top of the original post is very outdated now, and might not work properly for people not using the bash shell (which is no longer the default in macOS Catalina).

3 Likes

@techAPJ can we update/retest the OP?

Also once we are happy with the OP let’s nuke/integrate all the replies here cause it gets very confusing

7 Likes

Also, with ruby 2.7.0, there were multiple warnings while installing the script. 2.6.5 works fine though.

1 Like

I wonder how anyone keeps a development instance up to date, as it seems that re-running the install script won’t update stuff like ruby version.

I’ve also considered writing an ansible playbook rather than a shell script (I love shell scripts, but this seems like too hard a task). That would then make it possible to have a single cross platform install/maintenance script.

1 Like

The script is updated to install Ruby 2.6.5 and will accommodate both bash and zsh (default for macOS Catalina) shell.

6 Likes

After using for a long time my development stack fails… bundle exec rails server and output:

NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /Users/bekircem/.rvm/gems/ruby-2.4.1/specifications/msgpack-1.2.4.gemspec:19.
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /Users/bekircem/.rvm/gems/ruby-2.4.1/specifications/msgpack-1.2.4.gemspec:19.
NOTE: Gem::Specification#rubyforge_project= is deprecated with no replacement. It will be removed on or after 2019-12-01.
Gem::Specification#rubyforge_project= called from /Users/bekircem/.rvm/gems/ruby-2.4.1/specifications/msgpack-1.2.4.gemspec:19.
I, [2020-02-13T11:40:02.077202 #1107]  INFO -- : Refreshing Gem list
Traceback (most recent call last):
        37: from /Users/bekircem/discourse/bin/unicorn:49:in `<main>'
        36: from /Users/bekircem/discourse/bin/unicorn:49:in `load'
        35: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/unicorn-5.5.1/bin/unicorn:128:in `<top (required)>'
        34: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:141:in `start'
        33: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/unicorn-5.5.1/lib/unicorn/http_server.rb:794:in `build_app!'
        32: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/unicorn-5.5.1/lib/unicorn.rb:54:in `block in builder'
        31: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/unicorn-5.5.1/lib/unicorn.rb:54:in `eval'
        30: from config.ru:1:in `<main>'
        29: from config.ru:1:in `new'
        28: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/rack-2.0.7/lib/rack/builder.rb:55:in `initialize'
        27: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/rack-2.0.7/lib/rack/builder.rb:55:in `instance_eval'
        26: from config.ru:7:in `block in <main>'
        25: from config.ru:7:in `require'
        24: from /Users/bekircem/discourse/config/environment.rb:4:in `<top (required)>'
        23: from /Users/bekircem/discourse/config/environment.rb:4:in `require'
        22: from /Users/bekircem/discourse/config/application.rb:16:in `<top (required)>'
        21: from /Users/bekircem/discourse/config/application.rb:16:in `require'
        20: from /Users/bekircem/discourse/config/boot.rb:23:in `<top (required)>'
        19: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap.rb:30:in `setup'
        18: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/compile_cache.rb:9:in `setup'
        17: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:48:in `require_relative'
        16: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
        15: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
        14: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
        13: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        12: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
        11: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        10: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
         9: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
         8: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/compile_cache/iseq.rb:1:in `<top (required)>'
         7: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
         6: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
         5: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
         4: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
         3: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
         2: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
         1: from /Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/bekircem/.rvm/gems/ruby-2.4.1/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': no implicit conversion of String into Integer (TypeError)

Looks like this guide does not include yarn. Could you update @techAPJ? Thanks!

5 Likes

Sure, we’ll now install Yarn on macOS & Linux.

11 Likes

Hi! How can i remove all? Thanks

When I run bundle install the terminal says there is no command named “bundle.” Am I missing something?

1 Like

Follow the “Getting Started” guide:

gem install bundler

It said I don’t have permissions to write on the file, even though I’m on an administrator account.

Your user profile in bash isn’t the admin (or “root”) by default for your safety.
Re-run the same command with sudo to give permission:

sudo gem install bundler

Learn more about the basics of “bash,” the language of your Terminal.

Your terminal/shell has a small chance of not defaulting to bash. Here’s how to change your shell.

2 Likes