关于在 Ubuntu 20.04 上安装 Discourse 的说明

我正在处理 bundle install 步骤时遇到问题。这个错误一直出现。

(...)
正在安装 sassc-rails 2.1.2
正在安装 discourse-ember-rails 0.18.6
Gem::Ext::BuildError: 错误:无法构建 gem 原生扩展。

    当前目录:/home/archie/gems/gems/openssl-2.2.1/ext/openssl
/usr/bin/ruby3.0 -I /usr/lib/ruby/vendor_ruby -r
./siteconf20220430-16096-soaves.rb extconf.rb
检查 -lnsl 中的 t_open()... 否
检查 -lsocket 中的 socket()... 否
检查 openssl/ssl.h... 是
检查 -lcrypto 中的 CRYPTO_malloc()... 是
检查 -lssl 中的 SSL_new()... 是
检查 openssl/opensslv.h 中的 LIBRESSL_VERSION_NUMBER... 否
检查 OpenSSL 版本 >= 1.0.1 且 < 3.0.0... 否
*** extconf.rb 失败 ***
由于某种原因,无法创建 Makefile,可能是由于缺少必要的
库和/或头文件。请检查 mkmf.log 文件以获取更多详细信息。您可能
需要配置选项。

提供的配置选项:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/usr/bin/$(RUBY_BASE_NAME)3.0
	--with-openssl-dir
	--without-openssl-dir
	--with-openssl-include
	--without-openssl-include=${openssl-dir}/include
	--with-openssl-lib
	--without-openssl-lib=${openssl-dir}/lib
	--with-kerberos-dir
	--without-kerberos-dir
	--with-kerberos-include
	--without-kerberos-include=${kerberos-dir}/include
	--with-kerberos-lib
	--without-kerberos-lib=${kerberos-dir}/lib
	--with-debug
	--without-debug
	--enable-debug
	--disable-debug
	--with-nsl-dir
	--without-nsl-dir
	--with-nsl-include
	--without-nsl-include=${nsl-dir}/include
	--with-nsl-lib
	--without-nsl-lib=${nsl-dir}/lib
	--with-nsllib
	--without-nsllib
	--with-socket-dir
	--without-socket-dir
	--with-socket-include
	--without-socket-include=${socket-dir}/include
	--with-socket-lib
	--without-socket-lib=${socket-dir}/lib
	--with-socketlib
	--without-socketlib
	--with-openssl-config
	--without-openssl-config
	--with-pkg-config
	--without-pkg-config
	--with-crypto-dir
	--without-crypto-dir
	--with-crypto-include
	--without-crypto-include=${crypto-dir}/include
	--with-crypto-lib
	--without-crypto-lib=${crypto-dir}/lib
	--with-cryptolib
	--without-cryptolib
	--with-ssl-dir
	--without-ssl-dir
	--with-ssl-include
	--without-ssl-include=${ssl-dir}/include
	--with-ssl-lib
	--without-ssl-lib=${ssl-dir}/lib
	--with-ssllib
	--without-ssllib
extconf.rb:113:in `<main>':需要 OpenSSL >= 1.0.1 且 < 3.0.0 或 LibreSSL >= 2.5.0 (RuntimeError)

要查看此扩展为何无法编译,请检查 mkmf.log 文件,该文件可以在此处找到:

  /home/archie/gems/extensions/x86_64-linux/3.0.0/openssl-2.2.1/mkmf.log
extconf 失败,退出代码 1

Gem 文件将保留在 /home/archie/gems/gems/openssl-2.2.1 中以供检查。
结果已记录到
/home/archie/gems/extensions/x86_64-linux/3.0.0/openssl-2.2.1/gem_make.out

  /usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:95:in `run'
/usr/lib/ruby/vendor_ruby/rubygems/ext/ext_conf_builder.rb:47:in `block in
build'
  /usr/lib/ruby/3.0.0/tempfile.rb:317:in `open'
  /usr/lib/ruby/vendor_ruby/rubygems/ext/ext_conf_builder.rb:26:in `build'
  /usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:161:in `build_extension'
/usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:195:in `block in
build_extensions'
  /usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:192:in `each'
  /usr/lib/ruby/vendor_ruby/rubygems/ext/builder.rb:192:in `build_extensions'
  /usr/lib/ruby/vendor_ruby/rubygems/installer.rb:847:in `build_extensions'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/rubygems_gem_installer.rb:71:in
`build_extensions'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/rubygems_gem_installer.rb:28:in
`install'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/source/rubygems.rb:204:in
`install'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/installer/gem_installer.rb:54:in
`install'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/installer/parallel_installer.rb:186:in
`do_install'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/installer/parallel_installer.rb:177:in
`block in worker_pool'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:62:in
`apply_func'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:57:in
`block in process_queue'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:54:in
`loop'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:54:in
`process_queue'
/usr/share/rubygems-integration/all/gems/bundler-2.3.5/lib/bundler/worker.rb:91:in
`block (2 levels) in create_threads'

安装 openssl (2.2.1) 时出错,Bundler 无法继续。

在 Gemfile 中:
  cose 解析为 1.2.0,它依赖于
    openssl-signature_algorithm 解析为 1.1.1,它依赖于
      openssl
3 个赞

我最近也遇到了一个与 @Sonosus 类似的问题,发现这是由于最新版本的 Ubuntu (20.04) 预装了 OpenSSL 3.0.2 引起的。其他预装了 OpenSSL 的 Ubuntu/Debian 版本也可能存在这种情况。如果你遇到这个问题,你可能需要从源代码编译一个早期版本的 OpenSSL(我使用的是 OpenSSL-1.1.1n),然后重新运行 bundle install 命令。本质上,这个错误消息是关于 OpenSSL >= 1.0.1, < 3.0.0 的,结果发现 1.1 是唯一的替代方案。

你还需要使用 ruby --version 检查你正在使用的 Ruby 版本。Discourse 仍然使用 Ruby 2,所以如果你使用的是 Ruby 3.x 或更高版本,你需要使用一个早期版本。根据你安装 Ruby 的方式,你可能会在安装早期版本时遇到类似的 OpenSSL 问题,所以我建议在这里使用 Ruby 的版本管理器,我发现 Ruby 2.7.6 目前是与 Discourse 配合使用的最佳版本。

在全新安装 Ubuntu 20.04 后,我执行了以下操作才使 bundle install 正常运行:

安装 Discourse 依赖项、asdf 和克隆 Discourse

<(wget -qO- https://raw.githubusercontent.com/discourse/install-rails/master/linux)
sudo apt install build-essential checkinstall zlib1g-dev
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.10.0
git clone https://github.com/discourse/discourse.git ~/discourse

设置数据库

创建与你的 ubuntu 系统用户名 同名的角色

sudo -u postgres createuser -s "$USER"

从源代码安装 OpenSSL-1.1.1n

wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
tar -zxf openssl-1.1.1n.tar.gz && cd openssl-1.1.1n
./config --prefix=/opt/openssl-1.1.1n --openssldir=/opt/openssl-1.1.1n shared zlib
make
make test
make install
sudo rm -rf /opt/openssl-1.1.1n/certs
sudo ln -s /etc/ssl/certs /opt/openssl-1.1.1n

然后我将以下行添加到我的 .bashrc 文件中:

export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/openssl-1.1.1n/"

既然我们在这里,我也为 asdf 添加了以下行:

. $HOME/.asdf/asdf.sh
. $HOME/.asdf/completions/asdf.bash

保存并退出,然后:

source ~/.bashrc

安装 Ruby 2.7.6

asdf plugin add ruby
asdf install ruby 2.7.6

你现在可能可以运行 bundle install 了,但是,我在 Discourse 安装过程中遇到了另外几个问题,我在这里提及它们,以防其他人遇到。

安装 mini_racer 时出错

在安装 OpenSSL-1.1.1n 和 Ruby 2.7.6 后,运行 bundle install 时我一直遇到以下错误:

An error occurred while installing mini_racer (0.6.1), and Bundler cannot continue.

可以通过编辑 discourse/Gemfile 的本地版本中的以下行来解决:

并将其替换为:

gem 'mini_racer', github: 'rubyjs/mini_racer', branch: 'refs/pull/186/head'

在此步骤之后,我能够成功运行 bundle install

这类似于在 MacOS 上发生的问题,你可以在这里阅读更多关于它的信息:Install Discourse on macOS for development - #302 by blake

No such file or directory - convert

在 Discourse 安装的后期步骤中,我在运行 bundle exec rake autospec 时也遇到了以下问题:

Failures: 
  1. AboutController.index should display the about page for logged in user when login_required is true
    Failure/Error: expect(response.status).to eq(200)

    expected: 200
    got: 500

      (comparted using ==)
    #./spec/requests/about_controller_spec.rb:27:in 'block (3 levels) in <main>'
    #./spec/rails_helper.rb:277:in 'block (2 levels) in <top (required)>'
    #---------------------
    #---Caused by:---
    # Errno::ENOENT
    #  No such file or directory - convert
    # ./lib/letter_avatar.rb:105:in ``'

这个错误意味着 ImageMagick 包未安装(它提供了 convert 二进制文件)。

据说 Discourse 安装过程开始时的这个脚本应该包含所有必需的包,但看起来这个可能被排除了。

最后,通过 sudo apt install imagemagick 安装 ImageMagick 后,我成功地让我的 Discourse 服务器运行起来了!

希望这些信息对正在经历这个过程并遇到一些麻烦的人有所帮助。:smile:

5 个赞

谢谢,我稍后会试试看效果如何。

1 个赞