Notes about Installing Discourse on Ubuntu 20.04

I’m having trouble with the bundle install step. This error keeps coming up.

(...)
Installing sassc-rails 2.1.2
Installing discourse-ember-rails 0.18.6
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /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
checking for t_open() in -lnsl... no
checking for socket() in -lsocket... no
checking for openssl/ssl.h... yes
checking for CRYPTO_malloc() in -lcrypto... yes
checking for SSL_new() in -lssl... yes
checking for LIBRESSL_VERSION_NUMBER in openssl/opensslv.h... no
checking for OpenSSL version >= 1.0.1 and < 3.0.0... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--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 or LibreSSL >= 2.5.0 is
required (RuntimeError)

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

  /home/archie/gems/extensions/x86_64-linux/3.0.0/openssl-2.2.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/archie/gems/gems/openssl-2.2.1 for
inspection.
Results logged to
/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'

An error occurred while installing openssl (2.2.1), and Bundler cannot
continue.

In Gemfile:
  cose was resolved to 1.2.0, which depends on
    openssl-signature_algorithm was resolved to 1.1.1, which depends on
      openssl
3 Likes

I also recent ran into an issue similar to @Sonosus, and found that it was being caused by the latest version of Ubuntu (20.04) coming preinstalled with OpenSSL 3.0.2. This situation may also be present with other versions of Ubuntu/Debian that come preinstalled with OpenSSL. If you’re encountering this you’ll likely want to compile an earlier version of OpenSSL from source (I used OpenSSL-1.1.1n), and then re-run the bundle install command. Essentially, this error message is about OpenSSL >= 1.0.1, < 3.0.0, and turns out 1.1 is the only alternative.

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. Depending on how you’re installing Ruby, you’re likely to run into a similar OpenSSL issue with installing an earlier version, so I would recommend using a version manager for Ruby here, and I’ve found that Ruby 2.7.6 is currently the best version to use with Discourse.

After installing a fresh instance of Ubuntu 20.04, here’s what I did to get bundle install to run correctly:

Install Discourse Dependencies, asdf, and Clone Discourse

bash <(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

Setup Database

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

sudo -u postgres createuser -s "$USER"

Install OpenSSL-1.1.1n from Source

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

I then added the following line to my .bashrc file

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

While we’re here, I also added the following lines for asdf

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

Save and exit, and then

source ~/.bashrc

Install Ruby 2.7.6

asdf plugin add ruby
asdf install ruby 2.7.6

You might be good to run bundle install now, however, I ran into a couple other issues during the Discourse installation process that I’ll mention here for reference in case these happen to anyone else.

An error occurred while installing mini_racer

While running bundle install I kept running into after installing OpenSSL-1.1.1n and Ruby 2.7.6

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

Which can be solved by editing the following line in your local version of discourse/Gemfile:

And replacing it with

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

After this step I was able to get bundle install to run successfully.

This is similar to an issue happening on MacOS that you can read more about here

No such file or directory - convert

In the later steps of installing Discourse, I also ran into the following issue when running 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:inc ``'

This error means the ImageMagick package is not installed (it provides the convert binary)

Supposedly this script at the beginning of the Discourse install process should have all the necessary packages, but it looks like this one may have been excluded.

Finally, after installing ImageMagick with sudo apt install imagemagick I was able to get my Discourse server running successfully!

I hope this information is helpful to anyone who’s going through this process and having some trouble. :smile:

5 Likes

Thanks for this, I’ll give it a shot sometime and see how it goes.

1 Like