Installing Ruby 2.3.x on Ubuntu 18.04 is causing an error by the end of the installation process

gamofe picture gamofe · Apr 29, 2018 · Viewed 13.9k times · Source

I recently updated my system to Ubuntu 18.04 LTS, and since then, the Ruby version seems to have updated to 2.5. The issue is that, when attempting to deploy a project that uses Capistrano, it will now complain that Ruby 2.3 was not found.

The version it tries to install when running rvm install 2.3 is 2.3.4, and the first error that is shown is "Error running '__rvm_make -j4'". I tried removing RVM and installing again, but nothing solves this. The log is an enormous file which tells me nothing.

Then, I tried using rbenv, which also causes an error:

Installing ruby-2.3.4...

BUILD FAILED (Ubuntu 18.04 using ruby-build 20180424)

Inspect or clean up the working tree at /tmp/ruby-build.20180429172721.16258
Results logged to /tmp/ruby-build.20180429172721.16258.log

Last 10 log lines:
installing default nkf libraries
linking shared-object objspace.so
make[2]: Leaving directory '/tmp/ruby-build.20180429172721.16258/ruby-2.3.4/ext/objspace'
linking shared-object pathname.so
make[2]: Leaving directory '/tmp/ruby-build.20180429172721.16258/ruby-2.3.4/ext/pathname'
linking shared-object nkf.so
make[2]: Leaving directory '/tmp/ruby-build.20180429172721.16258/ruby-2.3.4/ext/nkf'
make[1]: Leaving directory '/tmp/ruby-build.20180429172721.16258/ruby-2.3.4'
uncommon.mk:203: recipe for target 'build-ext' failed
make: *** [build-ext] Error 2

The log file also has a stupid giant log file.

The next attempt was to install from source, which after running make within the folder, the error:

openssl_missing.h:78:35: error: macro "EVP_MD_CTX_create" passed 1 arguments, but takes just 0
 EVP_MD_CTX *EVP_MD_CTX_create(void);
                                   ^
In file included from /usr/include/openssl/x509.h:23:0,
                 from /usr/include/openssl/x509_vfy.h:17,
                 from openssl_missing.c:15:
openssl_missing.h:82:6: error: expected declaration specifiers or ‘...’ before ‘(’ token
 void EVP_MD_CTX_init(EVP_MD_CTX *ctx);
      ^
openssl_missing.h:90:6: error: expected declaration specifiers or ‘...’ before ‘(’ token
 void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
      ^
openssl_missing.c:39:23: error: macro "EVP_MD_CTX_create" passed 1 arguments, but takes just 0
 EVP_MD_CTX_create(void)
                       ^
openssl_missing.c:40:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
 {
 ^
openssl_missing.c: In function ‘EVP_MD_CTX_cleanup’:
openssl_missing.c:55:27: error: invalid application of ‘sizeof’ to incomplete type ‘EVP_MD_CTX {aka struct evp_md_ctx_st}’
     memset(ctx, 0, sizeof(EVP_MD_CTX));
                           ^~~~~~~~~~
In file included from /usr/include/openssl/x509.h:23:0,
                 from /usr/include/openssl/x509_vfy.h:17,
                 from openssl_missing.c:15:
openssl_missing.c: At top level:
openssl_missing.c:63:1: error: expected declaration specifiers or ‘...’ before ‘(’ token
 EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
 ^
openssl_missing.c:72:1: error: expected declaration specifiers or ‘...’ before ‘(’ token
 EVP_MD_CTX_init(EVP_MD_CTX *ctx)
 ^
openssl_missing.c: In function ‘HMAC_CTX_init’:
openssl_missing.c:82:25: error: dereferencing pointer to incomplete type ‘HMAC_CTX {aka struct hmac_ctx_st}’
     EVP_MD_CTX_init(&ctx->i_ctx);
                         ^
openssl_missing.c: In function ‘HMAC_CTX_cleanup’:
openssl_missing.c:95:27: error: invalid application of ‘sizeof’ to incomplete type ‘HMAC_CTX {aka struct hmac_ctx_st}’
     memset(ctx, 0, sizeof(HMAC_CTX));
                           ^~~~~~~~
Makefile:301: recipe for target 'openssl_missing.o' failed
make[2]: *** [openssl_missing.o] Error 1
make[2]: Leaving directory '/home/gabriel/Downloads/ruby-2.3.7/ext/openssl'
exts.mk:212: recipe for target 'ext/openssl/all' failed
make[1]: *** [ext/openssl/all] Error 2
make[1]: Leaving directory '/home/gabriel/Downloads/ruby-2.3.7'
uncommon.mk:203: recipe for target 'build-ext' failed
make: *** [build-ext] Error 2

What is it there to be done to install it? Or it isn't possible anymore to install these old versions?

Answer

guitarman picture guitarman · May 2, 2018

I had a same issue, though it seemed problem was in gcc, in my case problem was in libssl-dev, this is what helped me:

sudo apt purge libssl-dev && sudo apt install libssl1.0-dev

I use rbenv. If you use rvm, you might hit problem after running previous command:

/usr/share/rvm/scripts/base: No such file or directory

I recommend trying rbenv. After installing libssl1.0-dev, everything was flawless.