Set up Discourse for development on Fedora Linux

This guide has been tested against a fresh install of Fedora 31 and 33, but may work on older versions that also use dnf as the package management tool. This is not an official guide but may be useful for other developers using Fedora. This is largely based on the Ubuntu development guide, with changes for the different packages for dnf. The assumption is that you do not have any of the packages installed already, although most will be skipped by the tooling if it is already installed.

If you’re looking to install Discourse for a production environment, prefer the docker install instructions on github.

Install required system and development packages

sudo dnf update
sudo dnf install -y "@development-tools" git rpm-build zlib-devel ruby-devel readline-devel libpq-devel ImageMagick sqlite sqlite-devel nodejs npm curl gcc g++ bzip2 openssl-devel libyaml-devel libffi-devel zlib-devel gdbm-devel ncurses-devel optipng pngquant jhead jpegoptim gifsicle oxipng

Install required npm packages

sudo npm install -g svgo pnpm

Install and setup postgres

sudo dnf install postgresql-server postgresql-contrib
sudo postgresql-setup --initdb --unit postgresql
sudo systemctl enable postgresql
sudo systemctl start postgresql
sudo -u postgres -i createuser -s $USER

Install and setup redis

sudo dnf install redis
sudo systemctl enable redis
sudo systemctl start redis

Installing rbenv, ruby-build, and ruby

git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
~/.rbenv/bin/rbenv init
printf 'export PATH="$HOME/.rbenv/bin:$PATH"\n' >> ~/.bashrc
printf 'eval "$(rbenv init - --no-rehash)"\n' >> ~/.bashrc
source ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
# confirm the install is correct
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
rbenv install 2.7.1
rbenv global 2.7.1
rbenv rehash

Install Ruby dependencies

gem update --system
gem install bundler mailcatcher rails

Clone Discourse code

git clone https://github.com/discourse/discourse.git ~/discourse
cd ~/discourse

Install Discourse dependencies

bundle install
pnpm install

Create the required databases and load the schema

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

Test installation by running the tests

bundle exec rake autospec

Run the application

bundle exec rails server

You should now be able to see the Discourse setup page at http://localhost:3000.

For further setup, see the existing official install guides.


This document is version controlled - suggest changes on github.

26 Likes

In Installing rbenv, ruby-build, and ruby, the url to the rbenv-doctor script is not working anymore (apparently the branch has been rename from master to main), the correct command is now:

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash
2 Likes

Thanks for the info @nicolas-jaussaud, I’ve updated the OP.

FWIW I now prefer to use chruby and ruby-install over rbenv.

2 Likes

I ran into an issue trying to run bundle install as Fedora now has by default disabled file transport.

The error happens when trying to install the sprockets gem and ends with the message:

transport 'file' not allowed

I don’t know what’s the proper way to do this, but you can temporarily allow the unsafe transport:

git config --global protocol.file.allow always
# run the discourse setup here
git config --global protocol.file.allow never

After that I ran into an error like this when running db:migrate:

At /home/hhyyrylainen/Projects/discourse/lib/site_setting_extension.rb:199:in `public_send`
Deprecation notice: `SiteSetting.enable_personal_messages` has been deprecated. Please use `SiteSetting.personal_message_enabled_groups` instead. (removal in Discourse 3.0) 
At /home/hhyyrylainen/Projects/discourse/lib/site_setting_extension.rb:199:in `public_send`
#<Thread:0x00007f94c3342600 /home/hhyyrylainen/Projects/discourse/lib/scheduler/defer.rb:83 run> terminated with exception (report_on_exception is true):
/home/hhyyrylainen/.gem/ruby/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_handling.rb:309:in `connection_pool': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
	from /home/hhyyrylainen/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rails_multisite-4.0.1/lib/rails_multisite/connection_management/rails_61_compat.rb:8:in `current'
	from /home/hhyyrylainen/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rails_multisite-4.0.1/lib/rails_multisite/connection_management.rb:115:in `current_db_hostnames'
	from /home/hhyyrylainen/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rails_multisite-4.0.1/lib/rails_multisite/connection_management.rb:111:in `current_hostname'
	from /home/hhyyrylainen/Projects/discourse/lib/discourse.rb:232:in `handle_job_exception'
	from /home/hhyyrylainen/Projects/discourse/lib/scheduler/defer.rb:114:in `rescue in do_work'
	from /home/hhyyrylainen/Projects/discourse/lib/scheduler/defer.rb:113:in `do_work'
	from /home/hhyyrylainen/Projects/discourse/lib/scheduler/defer.rb:85:in `block (2 levels) in start_thread'
/home/hhyyrylainen/.gem/ruby/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/connection_handling.rb:309:in `connection_pool': ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished)
	from /home/hhyyrylainen/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/rails_multisite-4.0.1/lib/rails_multisite/connection_management.rb:79:in `with_connection'
	from /home/hhyyrylainen/Projects/discourse/lib/scheduler/defer.rb:96:in `do_work'
	from /home/hhyyrylainen/Projects/discourse/lib/scheduler/defer.rb:85:in `block (2 levels) in start_thread'

It seems it happened after the migration finished, so as I couldn’t figure out how to fix that I ignored it, but luckily my development site seems to be working.

For the test environment I didn’t get the same error but got an error about missing oxipng, which doesn’t seem to be available as a Fedora package.

After that I didn’t run into any more issues, everything still more or less worked fine on Fedora 38. Though, I had previously installed rbenv using some other setup instructions.

Running bundle exec rake autospec I got some test failures (135) but it seems I got a mostly working development setup.

2 Likes

I got the Dev version going some time ago but the Production version was too difficult for me . .

Just followed this guide to install on Fedora 40 Workstation, had to add oxipng to the distro installs.
sudo dnf install oxipng

3 Likes

Thanks for letting us know, I’ve updated the documentation in this commit: docs/fedora-setup: include oxipng package (#14) · discourse/discourse-developer-docs@eb51e54 · GitHub.

1 Like