$ rbenv install 2.3.1
Downloading ruby-2.3.1.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.bz2
Installing ruby-2.3.1...
BUILD FAILED (OS X 10.12 using ruby-build 20160602)
Inspect or clean up the working tree at /var/folders/5y/csxbdjv156n4fl25975s1x4w0000gn/T/ruby-build.20160921163419.48224
Results logged to /var/folders/5y/csxbdjv156n4fl25975s1x4w0000gn/T/ruby-build.20160921163419.48224.log
Last 10 log lines:
clock_id_t
/usr/include/mach/clock_types.h:53:13: note: 'clock_id_t' declared here
typedef int clock_id_t; /* clock identification type */
^
process.c:7500:19: warning: implicit declaration of function 'clock_getres' is invalid in C99 [-Wimplicit-function-declaration]
int ret = clock_getres(c, &ts);
^
2 warnings and 2 errors generated.
make: *** [process.o] Error 1
make: *** Waiting for unfinished jobs....
It looks like a change to the latest GCC. I see this patch to Ruby trunk has addressed the issue?
https://github.com/ruby/ruby/commit/fdaea1596a69997be845907641267cba0c607ad9
The last 10 log lines are showing a warning, but not the errors.
Could you include the build errors in /var/folders/5y/csxbdjv156n4fl25975s1x4w0000gn/T/ruby-build.20160921163419.48224.log ?
process.c:7360:9: error: unknown type name 'clockid_t'; did you mean 'clock_id_t'?
clockid_t c;
^~~~~~~~~
clock_id_t
/usr/include/mach/clock_types.h:53:13: note: 'clock_id_t' declared here
typedef int clock_id_t; /* clock identification type */
^
process.c:7362:15: warning: implicit declaration of function 'clock_gettime' is invalid in C99 [-Wimplicit-function-declaration]
ret = clock_gettime(c, &ts);
^
process.c:7499:9: error: unknown type name 'clockid_t'; did you mean 'clock_id_t'?
clockid_t c = NUM2CLOCKID(clk_id);
^~~~~~~~~
clock_id_t
/usr/include/mach/clock_types.h:53:13: note: 'clock_id_t' declared here
typedef int clock_id_t; /* clock identification type */
^
process.c:7500:19: warning: implicit declaration of function 'clock_getres' is invalid in C99 [-Wimplicit-function-declaration]
int ret = clock_getres(c, &ts);
^
2 warnings and 2 errors generated.
make: *** [process.o] Error 1
Puzzling:
checking for clockid_t... no
checking for convertible type of clockid_t... INT
But clockid_t is clearly checked for in time.h:
AC_CHECK_TYPES([clockid_t], [], [], [@%:@ifdef HAVE_TIME_H
@%:@ include <time.h>
@%:@endif
@%:@ifdef HAVE_SYS_TIME_H
@%:@ include <sys/time.h>
@%:@endif])
And it's available in /usr/include/time.h:
typedef enum {
…
} clockid_t;
What the heck?
Hm, I see the same config locally, but my compile goes through fine too.
Not seeing that typedef in /usr/include/time.h on a clean install of Sierra. For reference: https://gist.github.com/tylerjohnst/f45a53a9691301aafcdf6cfdb18a78b8
Fmm, I couldn't reproduce this with macOS Sierra and Xcode 8.0 release version.
I've figured out the issue:
Theres a bug with the App Store where Apple is pushing out updates to the Xcode7 version of the CLI tools that can update even if the Xcode8 version of the tooling is installed. This was causing the strange behavior in the header files.
Solution:
rm -rf /Library/Developer/CommandLineTools and reinstall the command line tools. Ruby builds correctly now.

For reference, this is what the App Store update looks like. It will go away after a few "refreshes" of the App Store. Hope this issue helps someone else out.
Whew! Thanks for tracking that down @tylerjohnst.
thanks 👍
Basically, it just didn't have write permission , use sudo rbenv install 2.3.1 and works fine
If it helps anyone, I fixed the error by running rm -rf /Library/Developer/CommandLineTools && xcode-select --install. That installs most recent Command Line Tools (8+) if you're running Sierra.
Great @tylerjohnst, you save my day!
Most helpful comment
I've figured out the issue:
Theres a bug with the App Store where Apple is pushing out updates to the Xcode7 version of the CLI tools that can update even if the Xcode8 version of the tooling is installed. This was causing the strange behavior in the header files.
Solution:
rm -rf /Library/Developer/CommandLineToolsand reinstall the command line tools. Ruby builds correctly now.