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
I have the same problem on ubuntu 17.10 for all ruby versions I have tried to install
Re-installing rbenv did not seem to help.
[UPDATE]
I succeeded to install Ruby 2.4.2 on the clean installed Ubuntu 16.04 Desktop.
It seems that something goes wrong on my working Ubuntu 16.04.
I will close this issue after researching just a little bit more.
I have not detected the root cause of the problem, I found a workaround:
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
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
I have the same problem. Apt-Get installed versiion on Ubuntu 17.10 is Ruby Build version: 20161225-1
No version of Ruby installs now through rbenv. Error reportd:
BUILD FAILED (Ubuntu 17.10 using ruby-build 20170914-5-gf41e847) .... ends in "segmentation fault, core dumped."
Since rbenv appears to have a gem version of ruby-build (did "gem update" under rbenv do this, because I did not?) I issued "gem uninstall ruby-build) and ran "rbenv install 2.3.1" using the Ubuntu installed version of Ruby-Build, but the same error and version number of Ruby-build appears.
Next step to is to uninstall + purge rbenv and to sea if Ubuntu supplied Ruby will be sufficient for my needs.
Purging rbenv and the ~/.rbenv directory and a clean install of rbenv performed.
Running "rbenv install 2.3.1" produced a similar error:

@casperl I think your problem is different from mine.
I don't encounter with any segmentation faults. My problem is related to linker.
@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
@kuroda that worked for me. Thanks!
Upon the release of Ruby 2.5.0, I tried to build on my Ubuntu 16.04. I got following error messages:
BUILD FAILED (Ubuntu 16.04 using ruby-build 20171215-3-ga97a138)
Inspect or clean up the working tree at /tmp/ruby-build.20171226020853.23177
Results logged to /tmp/ruby-build.20171226020853.23177.log
Last 10 log lines:
make[2]: Leaving directory '/tmp/ruby-build.20171226020853.23177/ruby-2.5.0/ext/digest/sha1'
exts.mk:259: recipe for target 'ext/digest/sha1/all' failed
make[1]: *** [ext/digest/sha1/all] Error 2
linking shared-object digest.so
make[2]: Leaving directory '/tmp/ruby-build.20171226020853.23177/ruby-2.5.0/ext/continuation'
make[2]: Leaving directory '/tmp/ruby-build.20171226020853.23177/ruby-2.5.0/ext/-test-/string'
make[2]: Leaving directory '/tmp/ruby-build.20171226020853.23177/ruby-2.5.0/ext/digest'
make[1]: Leaving directory '/tmp/ruby-build.20171226020853.23177/ruby-2.5.0'
uncommon.mk:240: recipe for target 'build-ext' failed
make: *** [build-ext] Error 2
As I did for Ruby 2.4.2, after building the openssl from the source, I succeeded to compile ruby with this command:
CONFIGURE_OPTS="--with-openssl-dir=/opt/openssl/1.1.0f" rbenv install 2.5.0
I am also getting the similar error, please could you help me.

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.
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`
I also faced this problem. This resource helped me to solve the problem.
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rvm-on-ubuntu-18-04
Can this issue not be closed, as both the gcc-6 and libssl dependencies for earlier Rubies are documented in the wiki (here and here)?
After installing gcc-6 and libssl1.0-dev I was able to install both pre and post 2.4 Rubies on Ubuntu 18.04 as per the solution offered by @kubakrzempek without a problem. BTW it appears I do have both libssl libraries installed:
$ /sbin/ldconfig -pv|grep libssl
libssl3.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libssl3.so
libssl.so.1.1 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libssl.so.1.1
libssl.so.1.0.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0
libssl.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libssl.so
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.
@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.
# 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.
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-6instead 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!
This issue was fixed at the first reporter.
Most helpful comment
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-6instead of the current upstream version (which is 7).So, usually it looks like that: