无法在Ubuntu 16.04中使用rbenv 2.3.1安装Ruby

时间:2017-08-18 11:00:15

标签: ruby-on-rails ubuntu-16.04

使用rbenv安装ruby以获取有关ruby构建的Ubuntu 16.04错误。 我已经尝试完全删除rbenv并再次重新安装rbenv,但是我得到以下错误。

我已按照DigitalOcean的程序安装了here中的rbenv,并按照here列出了ruby_build的步骤。我还安装了构建所需的所有依赖项。

在卸载和安装rbenv问题之后仍然是一样的问题。

   ~$ 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 (Ubuntu 16.04 using ruby-build 20170726-2-g254728e)

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

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

cat /tmp/ruby-build.20170818162042.1074.log的结果

In file included from ossl.h:57:0,
                 from ossl_bn.c:11:
/usr/include/openssl/asn1_mac.h:10:2: error: #error "This file is obsolete; please update your software."
 #error "This file is obsolete; please update your software."
  ^
In file included from ossl.h:221:0,
                 from ossl_bn.c:11:
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/x509v3.h:14,
                 from ossl.h:58,
                 from ossl_bn.c:11:
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);
      ^
ossl_bn.c: In function ‘ossl_bn_size’:
ossl_bn.c:43:19: error: invalid application of ‘sizeof’ to incomplete type ‘BIGNUM {aka struct bignum_st}’
     return sizeof(BIGNUM);
                   ^
ossl_bn.c: In function ‘ossl_bn_s_generate_prime’:
ossl_bn.c:769:5: warning: ‘BN_generate_prime’ is deprecated [-Wdeprecated-declarations]
     if (!BN_generate_prime(result, num, safe, add, rem, NULL, NULL)) {
     ^
In file included from /usr/include/openssl/bn.h:31:0,
                 from /usr/include/openssl/asn1.h:24,
                 from /usr/include/openssl/objects.h:916,
                 from /usr/include/openssl/evp.h:27,
                 from /usr/include/openssl/x509.h:23,
                 from /usr/include/openssl/x509v3.h:14,
                 from ossl.h:58,
                 from ossl_bn.c:11:
/usr/include/openssl/bn.h:285:1: note: declared here
 DEPRECATEDIN_0_9_8(BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
 ^
ossl_bn.c: In function ‘ossl_bn_is_prime’:
ossl_bn.c:877:5: warning: ‘BN_is_prime’ is deprecated [-Wdeprecated-declarations]
     switch (BN_is_prime(bn, checks, NULL, ossl_bn_ctx, NULL)) {
     ^
In file included from /usr/include/openssl/bn.h:31:0,
                 from /usr/include/openssl/asn1.h:24,
                 from /usr/include/openssl/objects.h:916,
                 from /usr/include/openssl/evp.h:27,
                 from /usr/include/openssl/x509.h:23,
                 from /usr/include/openssl/x509v3.h:14,
                 from ossl.h:58,
                 from ossl_bn.c:11:
/usr/include/openssl/bn.h:291:1: note: declared here
 DEPRECATEDIN_0_9_8(int
 ^
ossl_bn.c: In function ‘ossl_bn_is_prime_fasttest’:
ossl_bn.c:916:5: warning: ‘BN_is_prime_fasttest’ is deprecated [-Wdeprecated-declarations]
     switch (BN_is_prime_fasttest(bn, checks, NULL, ossl_bn_ctx, NULL, do_trial_division)) {
     ^
In file included from /usr/include/openssl/bn.h:31:0,
                 from /usr/include/openssl/asn1.h:24,
                 from /usr/include/openssl/objects.h:916,
                 from /usr/include/openssl/evp.h:27,
                 from /usr/include/openssl/x509.h:23,
                 from /usr/include/openssl/x509v3.h:14,
                 from ossl.h:58,
                 from ossl_bn.c:11:
/usr/include/openssl/bn.h:295:1: note: declared here
 DEPRECATEDIN_0_9_8(int
 ^
ossl_bn.c: In function ‘ossl_bn_size’:
ossl_bn.c:44:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
Makefile:301: recipe for target 'ossl_bn.o' failed

2 个答案:

答案 0 :(得分:1)

这是openssl和ruby 2.3.x的已知兼容性问题。

2.4之前的Ruby版本的openssl扩展与OpenSSL 1.1.x不兼容。目前,OpenSSL 1.1.0附带的大多数Linux发行版都有一个单独的OpenSSL 1.0.x包。

您需要安装早期版本的OpenSSL或使用ruby 2.4.x。

full description and solution here

答案 1 :(得分:1)

我能够使用以下Dockerfile

成功构建docker镜像
FROM ubuntu:16.04

ENV RBENV_ROOT=/usr/local/rbenv
ENV PATH=$RBENV_ROOT/bin:$RBENV_ROOT/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    cmake curl git zlib1g-dev \
    libssl-dev libreadline-dev \
    libyaml-dev libxml2-dev \
    libxslt-dev libsqlite3-dev \
    python-dev libxml2-dev \
    libxslt-dev groff zip \
    pkg-config ca-certificates \
    && apt-get clean

# Install rbenv
RUN git clone https://github.com/sstephenson/rbenv.git /usr/local/rbenv \
    && echo '# rbenv setup' > /etc/profile.d/rbenv.sh \
    && echo 'export RBENV_ROOT=/usr/local/rbenv' >> /etc/profile.d/rbenv.sh \
    && echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh \
    && echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh \
    && chmod +x /etc/profile.d/rbenv.sh

ENV RUBY_VERSION=2.3.1

# install ruby-build
RUN mkdir /usr/local/rbenv/plugins \
    && git clone https://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build \
    && /usr/local/rbenv/plugins/ruby-build/install.sh \
    && rbenv install ${RUBY_VERSION} \
    && rbenv global ${RUBY_VERSION} \
    && gem install bundler \
    && rbenv rehash

一些测试

$ docker run -it --rm test rbenv version
2.3.1 (set by /usr/local/rbenv/version)

$ docker run -it --rm test ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]