Ubuntu 及其较新的衍生产品带有 OpenSSL 3.0,在这种情况下,早于 3.1 的 Ruby 版本使用 OpenSSL 1.1
在这种情况下,最安全的选择是按照用户手册手动编译 OpenSSL 1.1。
它也适用于 Pop!_OS 和 asdf
sudo apt install build-essential checkinstall zlib1g-dev
cd ~/Downloads
wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
tar xf openssl-1.1.1n.tar.gz
cd ~/Downloads/openssl-1.1.1n
./config --prefix=/opt/openssl-1.1.1n --openssldir=/opt/openssl-1.1.1n shared zlib
make
make test
sudo make install
sudo rm -rf /opt/openssl-1.1.1n/certs
sudo ln -s /etc/ssl/certs /opt/openssl-1.1.1n
RUBY_CONFIGURE_OPTS=--with-openssl-dir=/opt/openssl-1.1.1n rbenv install 2.7.6
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=/opt/openssl-1.1.1n/"
Font: https://github.com/rbenv/ruby-build/discussions/1940#discussioncomment-2663209
compiling sha2init.c
compiling sha2.c
In file included from sha2.c:40:
sha2.c:578:28: warning: argument 2 of type 'sha2_byte[]' {aka 'unsigned char[]'} with mismatched bound [-Warray-parameter=]
578 | int SHA256_Final(sha2_byte digest[], SHA256_CTX* context) {
| ~~~~~~~~~~^~~~~~~~
sha2.h:145:50: note: in definition of macro 'SHA256_Final'
145 | #define SHA256_Final(d, c) SHA256_Finish(c, d)
| ^
sha2.h:170:18: note: previously declared as 'uint8_t[32]' {aka 'unsigned char[32]'}
170 | int SHA256_Final(uint8_t[SHA256_DIGEST_LENGTH], SHA256_CTX*);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sha2.h:145:50: note: in definition of macro 'SHA256_Final'
145 | #define SHA256_Final(d, c) SHA256_Finish(c, d)
| ^
sha2.c:643:44: warning: argument 2 of type 'char[]' with mismatched bound [-Warray-parameter=]
643 | char *SHA256_End(SHA256_CTX* context, char buffer[]) {
| ~~~~~^~~~~~~~
In file included from sha2.c:40:
sha2.h:171:31: note: previously declared as 'char[65]'
171 | char* SHA256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sha2.c:946:28: warning: argument 2 of type 'sha2_byte[]' {aka 'unsigned char[]'} with mismatched bound [-Warray-parameter=]
946 | int SHA512_Final(sha2_byte digest[], SHA512_CTX* context) {
| ~~~~~~~~~~^~~~~~~~
sha2.h:163:50: note: in definition of macro 'SHA512_Final'
163 | #define SHA512_Final(d, c) SHA512_Finish(c, d)
| ^
sha2.h:182:18: note: previously declared as 'uint8_t[64]' {aka 'unsigned char[64]'}
182 | int SHA512_Final(uint8_t[SHA512_DIGEST_LENGTH], SHA512_CTX*);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sha2.h:163:50: note: in definition of macro 'SHA512_Final'
163 | #define SHA512_Final(d, c) SHA512_Finish(c, d)
| ^
sha2.c:976:44: warning: argument 2 of type 'char[]' with mismatched bound [-Warray-parameter=]
976 | char *SHA512_End(SHA512_CTX* context, char buffer[]) {
| ~~~~~^~~~~~~~
In file included from sha2.c:40:
sha2.h:183:31: note: previously declared as 'char[129]'
183 | char* SHA512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sha2.c:1022:28: warning: argument 2 of type 'sha2_byte[]' {aka 'unsigned char[]'} with mismatched bound [-Warray-parameter=]
1022 | int SHA384_Final(sha2_byte digest[], SHA384_CTX* context) {
| ~~~~~~~~~~^~~~~~~~
sha2.h:154:50: note: in definition of macro 'SHA384_Final'
154 | #define SHA384_Final(d, c) SHA384_Finish(c, d)
| ^
sha2.h:176:18: note: previously declared as 'uint8_t[48]' {aka 'unsigned char[48]'}
176 | int SHA384_Final(uint8_t[SHA384_DIGEST_LENGTH], SHA384_CTX*);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sha2.h:154:50: note: in definition of macro 'SHA384_Final'
154 | #define SHA384_Final(d, c) SHA384_Finish(c, d)
| ^
sha2.c:1052:44: warning: argument 2 of type 'char[]' with mismatched bound [-Warray-parameter=]
1052 | char *SHA384_End(SHA384_CTX* context, char buffer[]) {
| ~~~~~^~~~~~~~
In file included from sha2.c:40:
sha2.h:177:31: note: previously declared as 'char[97]'
177 | char* SHA384_End(SHA384_CTX*, char[SHA384_DIGEST_STRING_LENGTH]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: note: unrecognized command-line option '-Wno-self-assign' may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option '-Wno-parentheses-equality' may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option '-Wno-constant-logical-operand' may have been intended to silence earlier diagnostics
linking shared-object digest/sha2.so
installing default sha2 libraries
make[2]: Leaving directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5/ext/digest/sha2'
make[2]: Entering directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5/ext/date'
compiling date_core.c
compiling date_parse.c
compiling date_strftime.c
compiling date_strptime.c
linking shared-object date_core.so
installing default date_core libraries
make[2]: Leaving directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5/ext/date'
make[2]: Entering directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5/ext/rubyvm'
installing default libraries
make[2]: Leaving directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5/ext/rubyvm'
make[2]: Entering directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5/ext/sdbm'
compiling _sdbm.c
compiling init.c
linking shared-object sdbm.so
make[2]: Leaving directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5/ext/sdbm'
make[2]: Entering directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5/ext/openssl'
compiling openssl_missing.c
compiling ossl.c
ossl.c: In function 'ossl_clear_error':
ossl.c:311:9: error: 'ERR_get_error_line_data' is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
311 | while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) {
| ^~~~~
In file included from ossl.h:21,
from ossl.c:10:
/usr/include/openssl/err.h:413:15: note: declared here
413 | unsigned long ERR_get_error_line_data(const char **file, int *line,
| ^~~~~~~~~~~~~~~~~~~~~~~
ossl.c: At top level:
cc1: note: unrecognized command-line option '-Wno-self-assign' may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option '-Wno-parentheses-equality' may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option '-Wno-constant-logical-operand' may have been intended to silence earlier diagnostics
cc1: some warnings being treated as errors
make[2]: *** [Makefile:313: ossl.o] Error 1
make[2]: Leaving directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5/ext/openssl'
make[1]: *** [exts.mk:244: ext/openssl/all] Error 2
make[1]: Leaving directory '/tmp/ruby-build.20221020135411.25.p0doc2/ruby-2.6.5'
make: *** [uncommon.mk:286: build-ext] Error 2