7
votes

I am trying to setup rbenv with a Dockerfile, but this just fails on rbenv install. I do have ruby-build in there, it just doesn't seem to work.

Relevant bits of the Dockerfile (largely lifted from https://gist.github.com/deepak/5925003):

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

# install ruby-build
RUN mkdir /usr/local/rbenv/plugins
RUN git clone https://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build

ENV PATH /usr/local/rbenv/shims:/usr/local/rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Set to Ruby 2.0.0-p247
RUN rbenv install 2.0.0-p247
RUN rbenv rehash
RUN rbenv local 2.0.0-p247

Error:

Step 21 : RUN rbenv install 2.0.0-p247
 ---> Running in 8869fa8f0651
rbenv: no such command `install'
Error build: The command [/bin/sh -c rbenv install 2.0.0-p247] returned a non-zero code: 1
The command [/bin/sh -c rbenv install 2.0.0-p247] returned a non-zero code: 1
2
Not to sound flippant, but are you really going to use more than one version of Ruby in a container? I'm tinkering with using rbenv based on your Dockerfile, and I'll keep tinkering but I'm wondering if we should just install the known version we want to use directly. I love rvm and rbenv, but Docker seems like an area you could reduce your dependencies.Kyle Kelley
No, but I do need it to use the correct version of Ruby, and not Ubuntu's package repo version. So it's either this, compiling from source, or rvm, and I'd rather avoid the latter two if possible. But you're right that it might just be better to just compile it from source.TheJF
Why not use ruby-install directly without rbenv? "If you have installed ruby-build as a standalone program, you can use the ruby-build command to compile and install Ruby versions into specific locations. Run the ruby-build command with the exact name of the version you want to install and the full path where you want to install it. For example, ruby-build 1.9.3-p448 ~/local/ruby-1.9.3-p448" (github.com/sstephenson/ruby-build)Niko
yes , put all the export staff into one file and then exec it is greate choice, should not use the RUNKewin

2 Answers

5
votes

You're missing a setup step for ruby-build: You need to run its install.sh after you cloned it.

0
votes

If you only need one Ruby version, just use the official Ruby images: https://hub.docker.com/_/ruby