在 Fedora Linux 上为开发设置 Discourse

本指南已在 Fedora 31 和 33 的全新安装上进行了测试,但可能也适用于使用 dnf 作为包管理工具的旧版本。这不是官方指南,但可能对使用 Fedora 的其他开发人员有用。这在很大程度上基于 Ubuntu 开发指南,并针对 dnf 的不同包进行了修改。假设您尚未安装任何这些包,尽管工具将跳过大多数已安装的包。

如果您希望为 生产环境 安装 Discourse,请参考 GitHub 上的 Docker 安装说明

安装所需的系统和开发包

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

安装所需的 npm 包

sudo npm install -g svgo pnpm

安装和设置 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

安装和设置 redis

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

安装 rbenv、ruby-build 和 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
# 确认安装正确
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

安装 Ruby 依赖项

gem update --system
gem install bundler mailcatcher rails

克隆 Discourse 代码

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

安装 Discourse 依赖项

bundle install
pnpm install

创建所需的数据库并加载 schema

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

通过运行测试来测试安装

bundle exec rake autospec

运行应用程序

bundle exec rails server

现在您应该可以在 http://localhost:3000 上看到 Discourse 设置页面。

有关进一步的设置,请参阅 现有的官方安装指南


本文档已版本控制 - 在 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 个赞