繁体   English   中英

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

[英]Cannot install Ruby with rbenv 2.3.1 in Ubuntu 16.04

当使用rbenv为Ubuntu 16.04安装ruby时,显示关于ruby构建的错误。 我试着完全删除rbenv,然后再次重新安装rbenv,但是我得到以下错误。

我已经按照DigitalOcean对安装rbenv在程序在这里 ,跟着列出的步骤这里的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

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

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

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

完整的说明和解决方案在这里

我能够使用以下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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM