ruby-build: Ruby 2.4.2 fails to build on Ubuntu 16.04

I have installed Ruby 2.4.1 successfully on my Ubuntu 16.04 Desktop, but failed to build Ruby 2.4.2.

Here are the last lines of error log:

make[2]: Entering directory '/tmp/ruby-build.20171106150424.32381/ruby-2.4.2/ext/digest/md5'
compiling md5init.c
linking shared-object digest/md5.so
/usr/bin/ld: /usr/local/lib/libcrypto.a(md5_dgst.o): relocation R_X86_64_PC32 against symbol `md5_block_asm_data_order' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:262: recipe for target '../../../.ext/x86_64-linux/digest/md5.so' failed
make[2]: *** [../../../.ext/x86_64-linux/digest/md5.so] Error 1
make[2]: Leaving directory '/tmp/ruby-build.20171106150424.32381/ruby-2.4.2/ext/digest/md5'
exts.mk:198: recipe for target 'ext/digest/md5/all' failed
make[1]: *** [ext/digest/md5/all] Error 2
make[1]: Leaving directory '/tmp/ruby-build.20171106150424.32381/ruby-2.4.2'
uncommon.mk:220: recipe for target 'build-ext' failed
make: *** [build-ext] Error 2

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 20 (2 by maintainers)

Commits related to this issue

Most upvoted comments

As far as I know, (and tested) Ruby versions < 2.4 requires libssl1.0, while >2.4 libssl1.1+. The two libssl packages conflict with each other, so you can’t have both of them, so I had to juggle the libs in order to install the required ruby version. To make things even funnier (or more complicated), Ruby <2.4 tends to require gcc-6 instead of the current upstream version (which is 7). So, usually it looks like that:

# for ruby <2.4
apt install libssl1.0-dev
CC=$(which gcc-6) rbenv install `version`

# for ruby >2.4
apt install libssl-dev
rbenv install `version`

@casperl

According to a bug report, you shoud type:

$ sudo apt-get install gcc-6 g++-6
$ CC=/usr/bin/gcc-6 rbenv install 2.3.1

I have not detected the root cause of the problem, I found a workaround:

  1. Build openssl from the source:
$ cd /tmp
$ curl -LO https://www.openssl.org/source/openssl-1.1.0f.tar.gz
$ tar xvfz openssl-1.1.0f.tar.gz
$ cd openssl-1.1.0f
$ ./config --prefix=/opt/openssl/1.1.0f
$ make
$ sudo make install
  1. Build ruby with CONFIGURE_OPTS environment variable:
$ CONFIGURE_OPTS="--with-openssl-dir=/opt/openssl/1.1.0f" rbenv install 2.4.2

[UPDATE]

You also need to install cacert.pem in order to make SSL connections:

$ sudo wget -O /opt/openssl/1.1.0f/ssl/cert.pem http://curl.haxx.se/ca/cacert.pem

Why should it be closed? What’s the point of using a tool that works with all ruby envs if you have to dive into the docs for a compile error? At the very least it should check for these dependencies before building and get them or tell you they are missing so you can install them.

# for ruby <2.4
apt install libssl1.0-dev
CC=$(which gcc-6) rbenv install `version`

# for ruby >2.4
apt install libssl-dev
rbenv install `version`

saved me installing an older Ruby version for a project I inherited.

Did you try to install this (below) list of dependency to your Ubuntu system ?: sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-de For me these stuff have fixed issue.

Purging rbenv and the ~/.rbenv directory and a clean install of rbenv performed. Running “rbenv install 2.3.1” produced a similar error: image

As far as I know, (and tested) Ruby versions < 2.4 requires libssl1.0, while >2.4 libssl1.1+. The two libssl packages conflict with each other, so you can’t have both of them, so I had to juggle the libs in order to install the required ruby version. To make things even funnier (or more complicated), Ruby <2.4 tends to require gcc-6 instead of the current upstream version (which is 7). So, usually it looks like that:

# for ruby <2.4
apt install libssl1.0-dev
CC=$(which gcc-6) rbenv install `version`

# for ruby >2.4
apt install libssl-dev
rbenv install `version`

You’re an angel!

@kuroda that worked for me. Thanks!

This issue was fixed at the first reporter.

@kubakrzempek

# for ruby <2.4
apt install libssl1.0-dev
CC=$(which gcc-6) rbenv install `version`

# for ruby >2.4
apt install libssl-dev
rbenv install `version`

this worked very well.