iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💎

Installing Ruby on Ubuntu 22.10 without rbenv

に公開

Ruby 3.1.3 / 3.0.5 / 2.7.7 have been released, so I installed them on Ubuntu 22.10, which I use daily.
I could use something like rbenv, but I don't typically use it.

Ruby 3.1.3

I didn't do anything special.

% tar xf ruby-3.1.3.tar.xz
% cd ruby-3.1.3
% ./configure --prefix=$HOME/ruby31 --with-ext=openssl,zlib,psych,dbm,gdbm,+
% make -j
% make install

Ruby 3.0.5

It does not support OpenSSL 3.0, so the openssl library cannot be compiled.

% tar xf ruby-3.0.5.tar.xz
% cd ruby-3.0.5
% ./configure --prefix=$HOME/ruby30 --with-ext=openssl,zlib,psych,dbm,gdbm,+
% make -j
...
*** Following extensions are not compiled:
openssl:
        Could not be configured. It will not be installed.
        /tmp/ruby-3.0.5/ext/openssl/extconf.rb:113: OpenSSL >= 1.0.1, < 3.0.0 or LibreSSL >= 2.5.0 is required
        Check ext/openssl/mkmf.log for more details.
*** Fix the problems, then remove these directories and try again if you want.
make[1]: *** [exts.mk:2234: note] エラー 1
make[1]: ディレクトリ '/tmp/ruby-3.0.5' から出ます
make: *** [uncommon.mk:301: build-ext] エラー 2

First, install it while excluding openssl from --with-ext.

% ./configure --prefix=$HOME/ruby30 --with-ext=zlib,psych,dbm,gdbm,+
% make -j
% make install

The latest openssl gem supports OpenSSL 3.0, so I will install that.
However, since the openssl library is required to connect to https://rubygems.org, it cannot be installed with gem install openssl.

% ~/ruby30/bin/gem install openssl
ERROR:  While executing gem ... (Gem::Exception)
    OpenSSL is not available. Install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources

Therefore, download the openssl gem using wget or curl.

% wget -q https://rubygems.org/downloads/openssl-3.0.1.gem
% curl -s https://rubygems.org/downloads/openssl-3.0.1.gem --output openssl-3.0.1.gem

After that, simply run gem install by specifying the file.

% ~/ruby30/bin/gem install openssl-3.0.1.gem
Building native extensions. This could take a while...
Successfully installed openssl-3.0.1
Parsing documentation for openssl-3.0.1
Installing ri documentation for openssl-3.0.1
Done installing documentation for openssl after 0 seconds
1 gem installed

Ruby 2.7.7

If I try to install it without building openssl, just as I did with Ruby 3.0, make install results in an error.

% tar xf ruby-2.7.7.tar.xz
% cd ruby-2.7.7
% ./configure --prefix=$HOME/ruby27 --with-ext=zlib,psych,dbm,gdbm,+
% make -j
% make install
...
/tmp/ruby-2.7.7/lib/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- openssl (LoadError)
make: *** [uncommon.mk:373: do-install-all] エラー 1

It might be a bit of a brute-force approach, but I managed to get it working by replacing ext/openssl with the openssl gem before building.
Since ext/digest seems to depend on openssl, I'll replace that as well.

% curl -s https://rubygems.org/downloads/openssl-3.0.1.gem --output openssl-3.0.1.gem
% curl -s https://rubygems.org/downloads/digest-3.1.0.gem --output digest-3.1.0.gem
% gem unpack openssl-3.0.1.gem
% gem unpack digest-3.1.0.gem
% tar xf ruby-2.7.7.tar.xz
% cd ruby-2.7.7
% rm -rf ext/openssl ext/digest
% rsync -a ../openssl-3.0.1/ext/openssl ./ext/
% rsync -a ../openssl-3.0.1/lib ./ext/openssl/
% rsync -a ../digest-3.1.0/ext/digest ./ext/
% rsync -a ../digest-3.1.0/lib ./ext/digest/
% ./configure --prefix=$HOME/ruby27 --with-ext=openssl,zlib,psych,dbm,gdbm,+
% make -j
% make install

By the way, it seems like rbenv installs openssl-1.1.1s and uses it for building.
Well, I think it's usually better to use rbenv.

Discussion