Your problem is Ubuntu 22.04 comes installed with OpenSSL 3.0, but the error message in your build log states:
OpenSSL >= 1.0.1, < 3.0.0 or LibreSSL >= 2.5.0 is required
To fix this you need to compile OpenSSL yourself. See the instructions below.
The answer was found here:
https://github.com/rbenv/ruby-build/discussions/1940
@wheatley @stuffa Based on this information, I would think that the safest way to build Ruby on Ubuntu 22.04 would be: instead of depending on the system libssl-dev package, download and compile OpenSSL 1.1.1 into its own directory, then point to that directory with
RUBY_CONFIGURE_OPTS=--with-openssl-dir=/path/to/my/openssl
while compiling with ruby-build.
The answer was found here:
https://github.com/rbenv/ruby-build/discussions/1940