Beginners Guide to Install Discourse on Ubuntu for Development

:warning: This guide covers installation instructions in development environment, for a production guide see: How to install Discourse in production (Discourse official install / standard install)


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

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

Although this guide assumes that you are using Ubuntu, but the set-up instructions will work fine for any Debian based distribution.

This guide has been confirmed to be working without the use of any additional steps on Ubuntu 18.

:exclamation: Depending on what version of Ubuntu/Debian you’re using to install Discourse, you may want to review the following:

Notes about Installing Discourse on Ubuntu 20.04 or later

By default, Ubuntu version 20.04 comes preinstalled with OpenSSL 3.0.2. You’ll likely want to compile an earlier version of OpenSSL from source (we recommend OpenSSL-1.1.1n). You’ll also want to check what version of Ruby you’re using with ruby --version Discourse still uses Ruby 2, so if you’re using Ruby 3.x or later you’ll need to use an earlier version. We recommend using a version manager for Ruby here, and we’ve found that Ruby 2.7.6 is currently the best version to use with Discourse. See Notes about Installing Discourse on Ubuntu 20.04 for more details about this.

Ubuntu 22.04 Warning for Early Adopters

This section added by @pfaffman 22.05.16 and should one day be wrong and the suggestion unnecessary.

NOTE: This won’t work for Ubuntu 22.04 just yet. If you are forced to use 22.04 (I was using Pop! OS), see Failed to build ruby 2.7.5 on ubuntu 22.04 · Discussion #1940 · rbenv/ruby-build · GitHub for how to compile a compatible version of openssl.

End of @pfaffman additions.

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/master/linux)

This will install following new packages on your system:

In case you have any of this package pre-installed and don’t want to run 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

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

sudo -u postgres createuser -s "$USER"

Bootstrap Discourse

Switch to your Discourse folder:

cd ~/discourse

Install the needed gems

source ~/.bashrc
bundle install

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

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

Try running the specs:

bundle exec rake autospec

All the tests should pass.

Start rails server:

bundle exec rails server

You should now be able to connect with your Discourse app on http://localhost:3000 - try it out!

Starting with Discourse 2.5+ EmberCLI is required in development and these additional steps will be required:

In a separate terminal instance, navigate to your discourse folder (cd ~/discourse) and run:

bin/ember-cli

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:

RAILS_ENV=development bundle exec rake 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 @AlexDev on 2022-05-26T19:00:00Z

43 Likes
Beginners Guide to Install Discourse on Windows 10 for Development
HOWTO Set up a development environment using vagrant (Ubuntu guide)
Docker setup for development
Share your Discourse dev setup
Discourse Development Contribution Guidelines
Discourse as Your First Rails App
Why is my dev server not showing me uploaded images in Topics?
How to open via internal IP?
Not receiving Activation Email
Jhead and svgo errors while running specs
Can't set up dev environment due to cppjieba_rb failing to install
Moderation Tools
How do I set up a local Discourse Development Environment?
Export only database data Postgres (for users, posts and topics)
Rspec failing to load when using the official beginners guide
Install Discourse on Ubuntu for Development
Attachment filename not set on download
[PAID] Import from Legacy Postgres DB
Dev Category sidebar
How to add a new language
Discourse Server logs show DB queries when I run the server
Using the Discourse API Ruby Gem
Does Gemfile need to include svg?
Does Gemfile need to include svg?
Find app.yml on unsupported-install
Setting up Discourse for development on Fedora Linux
Database wont migrate Discourse
I want to build a debug version of discourse
How To Use Screen To Bootstrap A Development Install (Ubuntu)
Can I install discourse on my local machine
How to reset discourse on dev mode? (w/o docker)
Migrating from Ning to Discourse
Beginners Guide to Install Discourse on Windows 10 for Development
Nodebb to Discourse
Beginners Guide to Install Discourse on Windows 10 for Development
Beginners Guide to Install Discourse on Windows 10 for Development
RSpec search_spec.rb RateLimiter LimitExceeded problems
Discourse as Your First Rails App
Issue with vagrant version following the dev guide
NULL first_visited_at dates in the topic_users table
Multiple instances. Visiting the second instance signs out the logged in account on the running instance
Can't run my Discourse locally
I want to install a plugin for development, what should I do?
Mini_racer installation issues on ubuntu vagrant (OSX)
Bundle exec rake fails
Vbulletin 4 import -
Hello from Gitpod! (installing on google cloud + automated dev setup)
How to Install Discourse on LocalHost in Windows?
Migration from Yahoo! Groups
Does the forum for development start up 24 hours*?
Two issues: Are they related to sidekiq? uninitialized constant Jobs::Jobs ::Scheduled (Discourse Newbie)
Bitnami Discourse VM on Virtualbox + SMTP mail-server for testing
How to allow customs hosts in development mode
Help with setting up discourse An error occurred while installing xorcist (1.1.2), and Bundler cannot continue
Any interest in Podman?
Beginners Guide to Install Discourse for Development using Docker
Bundler cannot continue due installation error of mini_racer 0.4.0
How to setup discourse in my local for development?
How might we better structure #howto?
Please help, how do I install Discourse on macOS?
How might we better structure #howto?
Can't reach Discourse server in VM from Host
Importing / migrating MyBB to Discourse
Beginner’s Guide to Creating Discourse Plugins Part 6: Acceptance Tests
Images are not being populated in discourse
Installing Plugins in Discourse Development Install
Beginner's Guide to Creating Discourse Plugins Part 1: Creating a basic plugin
Discourse Local setup
Is this correct? How long to install dev Version?
Overriding user_guardian.rb in a plugin (no fork necessary!)
Overriding user_guardian.rb in a plugin (no fork necessary!)
Importing / migrating from Kunena 3
Importing / migrating Phorum to Discourse
Importing / migrating MyBB to Discourse
Importing / migrating from FluxBB
Importing / migrating PunBB to Discourse
Importing / migrating NodeBB (MongoDB) to Discourse
Importing / migrating from vBulletin 4
Importing / migrating NodeBB (Redis) to Discourse
Importing / migrating from phpBB3
How Sam's Windows development environment is configured
Site setting is different Every time on Ubuntu development installation
Problems with understanding the development of Discourse
How do I change the address in the database?
Discourse on local pc
Error while importing topics from Flarum (users, groups import OK)
Unable to Install Discourse for development
Flarum To Discourse Migration
Problem in development Installation
Beginners Guide to Install Discourse on macOS for Development
Calling out for Testers
Problem in development Installation
Developing on the mobile version of Discourse
Can't build Discourse on Ubuntu 20.10
Errno::EACCES: Permission denied on new Ubuntu development setup
Discourse standalone
How to install Discourse locally?
Importing / migrating MyBB to Discourse
Docker in VMWare - How to access to Discourse
How can I make my own Discourse plugins?
Beginners Guide to Install Discourse on Windows 10 for Development
What is the latest recommended workflow for local development? (Ubuntu 16.04)
What is the latest recommended workflow for local development? (Ubuntu 16.04)
How to customize the Discourse app using docker container?
Update PhantomJS to latest for Ubuntu dev guide?
A check for updates has not been performed lately. Ensure sidekiq is running
How to fix bundler executable conflicts in the `techAPJ/install-rails` script?
Ubuntu development install: Permission denied @ apply2files
Install discourse on localhost
Trouble getting a top level page to Ember
Formal german available?
Any interest in Podman?
Rake aborted message is showing when installing vagrant development
Where is the db connection information discourse?
How to install the bootsnap gem?
Google Groups Import Script Fails (Due to Invalid Browser)
Migrating from GetSatisfaction to Discourse
State of disqus to discourse importer
Connecting to Droplet
Connecting to Droplet
Migrating from bbPress WordPress plugin to Discourse
Beginners Guide to Install Discourse on Windows 10 for Development
Install and import Mysql on the development environment
Can't uninstall on Ubuntu 18.04
Migrating to Discourse from another Forum software
How to install Discourse on windows
Share your Discourse dev setup
Discourse running very slow on local machine
Override profile background via SSO
Can't find the Discourse folder inside virtual box via ssh
Importing MyBB database to Discourse
How to install Discourse on windows
How to create new user with verified email in development mode?
Issue in setup discourse on ubuntu server
Unable to create Vagrant local installation
Installing problem - bundle install
How to get a docker image of discourse using bash on windows 10?

This looks like it installs node 14, but node 16 is required.

I am not sure what I did to get my installation to stop saying:

(reverse-i-search)`eme': discourse_theme watch search-google-group-th^Ce/                                                          
 (main) pfaffman@noreno:~/src/discourse-repos/discourse$ ./bin/ember-cli                                                           
error discourse@0.0.0: The engine "node" is incompatible with this module. Expected version "16.* || >= 18". Got "14.19.3"         
error Found incompatible module.       

Does anyone else wish that there were an Ansible playbook that would manage all of these dependencies?

2 Likes

I think in the script to install dependencies the Node.js version to install has to be changed to at least v16. Currently it installs v14 and I get the same error as @paffman:

log_info "Installing Node.js 14 ..."
  curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
  sudo apt-get -y install nodejs
  sudo npm install -g svgo
  sudo npm install -g yarn
1 Like

Hey guys,

I’m trying to

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

but I constantly get the following error:

connection to server at "127.0.0.1", port 5432 failed: fe_sendauth: no password supplied
Couldn't create 'discourse_test' database. Please check your configuration.
rake aborted!
ActiveRecord::ConnectionNotEstablished: connection to server at "127.0.0.1", port 5432 failed: fe_sendauth: no password supplied


Caused by:
PG::ConnectionBad: connection to server at "127.0.0.1", port 5432 failed: fe_sendauth: no password supplied

Tasks: TOP => db:create
(See full trace by running task with --trace)
DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set
`legacy_connection_handling` to `false` in your application.

The new connection handling does not support `connection_handlers`
getter and setter

I’m really confused by the “connection to server at “127.0.0.1”, port 5432 failed: fe_sendauth: no password supplied”. You’re my last hope :slight_smile:

I’m using Ubuntu 22.04

Hey, just chiming in to mention I’m suffering from the exact same issue as Andrew, I had mentioned my problem in the thread for Beginners Guide to Install Discourse on Windows 10 for Development.

Evidently it’s an issue unrelated to Ubuntu, I have tried 18.04 and 20.04, and Andrew is using 22.04, I know I’ve never had this issue on older versions of Discourse. Did you recently push an update or has something changed? Clearly something’s fishy about the bundle exec rake db:create command.

I’m getting the same error too. Were you able to find a solution?

Unfortunately not, I’m assuming this won’t get resolved for some time.

1 Like

@CvX The db rake tasks seem to be broken since DEV: Improve multisite db scripts in dev (#17337) · discourse/discourse@2e4056d · GitHub. I just tested it without a multisite config on a fresh install.

Created database 'discourse_development'
Created database 'discourse_test'
Created database 'discourse_test_multisite'
Failed to validate the schema cache because of ActiveRecord::ConnectionNotEstablished: connection to server at "127.0.0.1", port 5432 failed: fe_sendauth: no password supplied
connection to server at "127.0.0.1", port 5432 failed: fe_sendauth: no password supplied
Couldn't create 'discourse_development' database. Please check your configuration.
rake aborted!
ActiveRecord::ConnectionNotEstablished: connection to server at "127.0.0.1", port 5432 failed: fe_sendauth: no password supplied
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:87:in `rescue in new_client'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:77:in `new_client'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/connection_handling.rb:280:in `connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/postgresql_database_tasks.rb:12:in `connection'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/postgresql_database_tasks.rb:26:in `create'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/database_tasks.rb:122:in `create'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/database_tasks.rb:184:in `block in create_current'
/home/gerhard/.gem/ruby/2.7.6/gems/discourse_dev_assets-0.0.4/lib/discourse_dev_assets.rb:27:in `block in each_current_configuration'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/database_tasks.rb:557:in `block (2 levels) in each_current_configuration'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/database_tasks.rb:554:in `each'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/database_tasks.rb:554:in `block in each_current_configuration'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/database_tasks.rb:553:in `each'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/database_tasks.rb:553:in `each_current_configuration'
/home/gerhard/.gem/ruby/2.7.6/gems/discourse_dev_assets-0.0.4/lib/discourse_dev_assets.rb:22:in `each_current_configuration'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/tasks/database_tasks.rb:184:in `create_current'
/home/gerhard/.gem/ruby/2.7.6/gems/activerecord-7.0.3.1/lib/active_record/railties/databases.rake:45:in `block (2 levels) in <main>'
/home/gerhard/.gem/ruby/2.7.6/gems/rake-13.0.6/exe/rake:27:in `<top (required)>'

Reverting that commit makes it work again.

2 Likes

I installed the previous branch.

git clone https://github.com/discourse/discourse.git --branch Minor-css-fix ~/discourse

The point I’m stuck at now is when I start with bin/ember-cli after creating an admin account, I get a Proxy Error.

Have you started the rails server in another terminal?

UNICORN_BIND_ALL=true rails s

1 Like

Was it that easy? :slight_smile: Thank you very much.

1 Like

I went through this guide in a fresh install of Ubuntu and ran into quite a few issues (node was out of date, tests failing in bundle exec rake autospec), and I haven’t gotten past that second issue yet.

The guide was originally written in 2014, maybe it’s time for Discourse to update these guides? I’d like to contribute to plugin development but I’ve spent a few days now just attempting to get a development environment configured.

The guides are updated regularly. :+1: If you look at the timestamp in the top-right you can see it was last done 26 May, and if you click on the edit history next to it you should be able to view any changes that were made.

However, if you still think something is incorrect/out-of-date it’s a wiki post and you can dive in yourself and make any changes you think it needs. :slight_smile: (or, if you’d prefer, add them as a post to the topic for review/confirmation first :+1:)

2 Likes

if you have issues I recommend trying the docker guide. It is great :grinning: :+1:

1 Like