Install Discourse on Ubuntu or Debian for Development

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


So you want to set up Discourse on Ubuntu or Debian to hack on and develop with?

We’ll assume that you work locally and don’t have Ruby/Rails/Postgres/Redis installed on your Ubuntu or Debian system. Let’s begin!

Requirements

We suggest having at least 4 GB RAM and 2 CPU cores.

Current compatibility:

OS Compatibility
Debian 11 :white_check_mark:
Crostini (Linux on ChromeOS) :white_check_mark:
Ubuntu 22.04 or later :white_check_mark:

Install Discourse Dependencies

As regular user run this script in terminal, to setup Rails development environment:-

bash <(wget -qO- https://raw.githubusercontent.com/discourse/install-rails/main/linux)

This will install the following new packages on your system:

In case you have any of this package pre-installed and don’t want to run the entire script, see the script and pick the packages you don’t have currently installed. The script is fine-tuned for Discourse, and includes all the packages required for Discourse installation.

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

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

Already completed by the install script

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

cd /tmp && sudo -u postgres createuser -s "$USER"

Bootstrap Discourse

Switch to your Discourse folder:

 cd ~/discourse

Install the needed gems

source ~/.bashrc
bundle install

Install the JS dependencies

yarn install

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

bin/rails db:create 
bin/rails db:migrate
RAILS_ENV=test bin/rails db:create db:migrate

Start rails and ember server:

bin/ember-cli -u

If the images are not appearing, use this command instead:
(you can also specify an IP if you are working on a remote server)

DISCOURSE_HOSTNAME=localhost UNICORN_LISTENER=localhost:3000 bin/ember-cli -u

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

Create New Admin

To create a new admin, run the following command:

bin/rails admin:create

Follow the prompts, and a new admin account will be created.

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.


Last Reviewed by @blake on 2023-04-03T06:00:00Z

Last edited by @JammyDodger 2024-05-25T08:33:27Z

Check documentPerform check on document:
63 Likes

fixed it by removing the calendar plugin. :thinking:

3 Likes

install is very slow

I’ve been trying for about 45min to get it to connect to my local DB but can’t figure it out:

discourse $bin/rails db:create
We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml

Here is the full trace:

discourse $bin/rails db:create --trace
** Invoke db:create (first_time)
** Invoke db:force_skip_persist (first_time)
** Execute db:force_skip_persist
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:create
We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml.

To resolve this issue:

- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

        bin/rails db:create
Couldn't create 'discourse_development' database. Please check your configuration.
rails aborted!
ActiveRecord::NoDatabaseError: We could not find your database: postgres. Which can be found in the database configuration file located at config/database.yml. (ActiveRecord::NoDatabaseError)

To resolve this issue:

- Did you create the database for this app, or delete it? You may need to create your database.
- Has the database name changed? Check your database.yml config has the correct database name.

To create your database, run:

        bin/rails db:create
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/postgresql_adapter.rb:81:in `rescue in new_client'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_handling.rb:280:in `connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:122:in `create'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:184:in `block in create_current'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/discourse_dev_assets-0.0.4/lib/discourse_dev_assets.rb:27:in `block in each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:557:in `block (2 levels) in each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:554:in `each'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:554:in `block in each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:553:in `each'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:553:in `each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/discourse_dev_assets-0.0.4/lib/discourse_dev_assets.rb:22:in `each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:184:in `create_current'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <main>'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `block in execute'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `each'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `execute'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:188:in `invoke'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:188:in `invoke_task'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `each'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block in top_level'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:147:in `run_with_threads'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:132:in `top_level'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/rake_module.rb:59:in `with_application'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/command.rb:51:in `invoke'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/commands.rb:18:in `<main>'
<internal:/home/dylan/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/home/dylan/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:18:in `<main>'

Caused by:
PG::ConnectionBad: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: fe_sendauth: no password supplied (PG::ConnectionBad)
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/pg-1.5.4/lib/pg/connection.rb:696:in `async_connect_or_reset'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/pg-1.5.4/lib/pg/connection.rb:824:in `connect_to_hosts'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/pg-1.5.4/lib/pg/connection.rb:759:in `new'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/pg-1.5.4/lib/pg.rb:63:in `connect'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/postgresql_adapter.rb:78:in `new_client'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/connection_handling.rb:280:in `connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:122:in `create'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:184:in `block in create_current'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/discourse_dev_assets-0.0.4/lib/discourse_dev_assets.rb:27:in `block in each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:557:in `block (2 levels) in each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:554:in `each'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:554:in `block in each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:553:in `each'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:553:in `each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/discourse_dev_assets-0.0.4/lib/discourse_dev_assets.rb:22:in `each_current_configuration'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/tasks/database_tasks.rb:184:in `create_current'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-7.0.8.1/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <main>'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `block in execute'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `each'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:281:in `execute'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `synchronize'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/task.rb:188:in `invoke'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:188:in `invoke_task'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `each'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:138:in `block in top_level'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:147:in `run_with_threads'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:132:in `top_level'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/application.rb:214:in `standard_exception_handling'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rake-13.2.1/lib/rake/rake_module.rb:59:in `with_application'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/command.rb:51:in `invoke'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/railties-7.0.8.1/lib/rails/commands.rb:18:in `<main>'
<internal:/home/dylan/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/home/dylan/.rbenv/versions/3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/home/dylan/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:18:in `<main>'
Tasks: TOP => db:create