在 Fedora Linux 上为开发设置 Discourse

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.

27 个赞

Installing rbenv, ruby-build, and ruby 中,rbenv-doctor 脚本的 url 不再有效(显然分支已从 master 重命名为 main),现在的正确命令是:

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

感谢 @nicolas-jaussaud 提供的信息,我已经更新了 OP。

供参考,我现在更倾向于使用 chrubyruby-install 而不是 rbenv

2 个赞

在运行 bundle install 时遇到了一个问题,因为 Fedora 现在默认禁用了文件传输。

问题发生在尝试安装 sprockets gem 时,最后的消息是:

transport 'file' not allowed

我不知道正确的方法是什么,但你可以暂时允许不安全传输:

git config --global protocol.file.allow always
# 在这里运行 discourse setup
git config --global protocol.file.allow never

之后,在运行 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'

似乎是在迁移完成后发生的,所以我无法弄清楚如何修复它,就忽略了它,但幸运的是我的开发站点似乎还在工作。

对于测试环境,我没有遇到同样的错误,但遇到了关于缺少 oxipng 的错误,而 oxipng 似乎在 Fedora 包中不可用。

之后我没有再遇到任何问题,一切在 Fedora 38 上仍然或多或少地正常工作。不过,我之前是按照一些其他设置说明安装的 rbenv。

运行 bundle exec rake autospec 时,我遇到了一些测试失败(135个),但似乎我得到了一个基本可用的开发设置。

2 个赞

我之前已经成功运行了开发版本,但生产版本对我来说太难了。

刚刚按照本指南在 Fedora 40 Workstation 上进行了安装,不得不将 oxipng 添加到发行版安装中。
sudo dnf install oxipng

3 个赞

感谢告知,我已在本次提交中更新了文档:https://github.com/discourse/discourse-developer-docs/commit/eb51e543efb91b4efb1974625e69c41846832039。

1 个赞

今天在 Fedora 41 上安装后,当我连接到 localhost:3000 并点击注册时,我遇到了以下问题:
“设置过程中未定义管理员电子邮件”;消息提供了如何添加管理员电子邮件。

我按照以下步骤操作,但未能成功添加管理员帐户,因为在使用 ./launcher enter app 时出现了 2 个错误:
1° 首先解决的错误是:不存在 app.yml 文件 – 我将 sampleapp.yml 从 sample 文件夹复制到 container 文件夹,然后修改以添加电子邮件地址,然后使用 /var/discourse/launcher rebuild app 进行重建
2° 第二个错误尚未解决:
来自守护进程的错误响应:没有这样的容器:app
如果我使用 rake 命令创建管理员,它会告诉我找不到 rakefile

有人能帮忙吗?

此安装不使用 docker,因此您无法进入容器。

尝试使用以下命令从 Discourse 文件夹创建管理员:

bin/rails admin:create
1 个赞

你好椰子,你的回应很快,效率很高,非常感谢!
命令返回 gem bunder 缺失,我已使用 gem install bundler -v 2.6.2 安装,然后我就可以成功应用你的解决方案了!

2 个赞

在尝试本地安装时遇到了 pgvector 的问题。这是发生在 Fedora 42 和 Postgres16 上。打包的 pgvector 版本是 0.6.2,似乎我需要从源代码编译才能获得更新的版本。

然后,在构建 pgvector 时遇到了冲突,它似乎需要 postgresql-private-devel 包,该包与 libpq-devel 有冲突的请求。

通过以下方式解决:

  •  sudo dnf install postgresql-server-devel --allowerasing
    
  • 构建 pgvector
  • 检查已安装的版本
    sudo -u postgres psql discourse_development -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';"
    
  •  sudo systemctl restart postgresql
    
2 个赞