Using rbenv with Docker - ruby-on-rails

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

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

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

Related

How to install ruby 3.1.2 in an Ubuntu Docker container?

I tried:
if ! command -v ruby &> /dev/null
then
# - proverbot's version
# First, install Ruby, as that is for some reason required to build
# the "system" project
# git clone https://github.com/rbenv/ruby-build.git ~/ruby-build
# mkdir -p ~/.local
# PREFIX=~/.local ./ruby-build/install.sh
# ~/.local/ruby-build 3.1.2 ~/.local/
# - u-pycoq's version
# sudo apt-get install ruby-full
sudo apt-get install rbenv
rbenv init
eval "$(rbenv init - bash)"
echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc
sudo apt-get install ruby-build
# ruby-build 3.1.2
rbenv install 3.1.2
rbenv global 3.1.2
ruby -v
else
echo "Error: failed to install ruby"
fi
But I get my Ruby build is not up-to-date perhaps, but when I install it, it is up-to-date. Therefore, why is the proverbot's attempt 3.1.2 if it doesn't exist?
It was inspired from: https://superuser.com/questions/340490/how-to-install-and-use-different-versions-of-ruby
It seems it works with 2.7.1, but not with 3.1.2.
sudo apt-get install rbenv
rbenv init
eval "$(rbenv init - bash)"
echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc
sudo apt-get install ruby-build
# mkdir -p ~/.local
# PREFIX=~/.local
# sh ~/ruby-build/install.sh
mkdir -p ~/.local
ruby-build 2.7.1 ~/.local
rbenv global 2.7.1
# ruby-build 2.3.1p112 ~/.local/
# ruby-build 3.1.2 ~/.local/
# rbenv global 3.1.2
ruby -v
bot#513314bdda2a:~/ruby-build$ ruby -v
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [aarch64-linux-gnu]
Main command that fails
I think this is the main command that fails after rbenv and ruby-build are installed:
rbenv install 3.1.2
with
ruby-build: definition not found: 3.1.2
See all available versions with `rbenv install --list.
If the version you need is missing, try upgrading ruby-build.
Might my version of Ubuntu be the issue?
I tried it in a different server outside my Docker container and Ruby works. In the Docker container it says it's:
bot#513314bdda2a:~/ruby-build$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Is that an issue?
I tried updating ruby-build
I ran sudo apt-get update then sudo apt-get upgrade ruby-build then mkdir -p ~/.local then ruby-build 3.1.2 ~/.local/ and the error is ruby-build: definition not found: 3.1.2
I tried a bunch of Ubuntu's, but it failed
#!/usr/bin/env bash
# - Get the Ubuntu version for the Ubuntu image
#docker run -it --rm ubuntu:20.04 /bin/bash
docker run -it --rm ubuntu:18.04 /bin/bash
apt-get update && apt-get install -y lsb-release && apt-get clean all
lsb_release -a
#apt-get install git
apt-get update
apt-get upgrade ruby-build
apt-get install rbenv
apt-get install ruby-build
rbenv install 3.1.2
# - Get Ubuntu version for the 'miniconda3' Docker image
docker run -it --rm continuumio/miniconda3:latest /bin/bash
#sudo apt-get install lsb-release
#apt-get install lsb-release
apt-get update && apt-get install -y lsb-release && apt-get clean all
lsb_release -a
Output of ruby-build https://gist.github.com/brando90/8a40e83df107f5a915ba105d9fb0121c
$ ruby-build --definitions
1.8.5-p52
1.8.5-p113
...
The gist is that all 3.x.x are missing.
I tried updating ruby-build manually, but it failed
I did do:
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
then
git -C "$(rbenv root)"/plugins/ruby-build pull
Then I installed 3.1.2 with rbenv. It seemed to succeed, but then ruby --version doesn't seem right(?).
bot#e3a50e4f740f:~$ rbenv install 3.1.2
To follow progress, use 'tail -f /tmp/ruby-build.20221207002433.1304.log' or pass --verbose
Downloading ruby-3.1.2.tar.gz...
-> https://cache.ruby-lang.org/pub/ruby/3.1/ruby-3.1.2.tar.gz
Installing ruby-3.1.2...
Installed ruby-3.1.2 to /home/bot/.rbenv/versions/3.1.2
bot#e3a50e4f740f:~$ ruby --version
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [aarch64-linux-gnu]
bot#e3a50e4f740f:~$ rbenv global 3.1.2
bot#e3a50e4f740f:~$ ruby --version
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [aarch64-linux-gnu]
Option: Official rbenv instructions
Alas, that didn't work :frowning:
$ rbenv install 3.1.2
rbenv: no such command `install'
I did:
mkdir ~/.rbenv
cd ~/.rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
bash
# exec $SHELL
rbenv install 3.1.2
Using the official instructions: Seamlessly manage your app’s Ruby environment with rbenv, Basic Git Checkout
Is it probably best to use a Ruby Docker container? But how do I get one with the specific version I want 3.1.2 (or any specific version)?
All options I tried to install ruby on a Docker container with specific version 3.1.2, likely better to just use a Ruby image instead, any recommendations for 3.1.2?
An idea for a bounty: force insert the FROM ruby:3.1.2 image into running container
I still can't install Ruby on a already-running container :(, is it possible to layer on top of the running image the ruby 3.1.2 image into the running container?
References:
Crossposted: Why can't I install Ruby 3.1.2 in a Linux Docker container?
All attempts are documented at ruby_install_ubuntu.sh - the Discord channel for Ruby was really helpful, even though we didn't solve it: https://discord.com/channels/518658712081268738/650031651845308419
This doesn't work on an Ubuntu Docker container which is the title of the question, but it at least worked on the HPC with Ubuntu I was using, so it can still be useful for future readers, a real answer on an Ubuntu Docker container is still needed and wanted.
# - install rbenv for installing the Ruby interpreter
mkdir ~/.rbenv
cd ~/.rbenv
git clone https://github.com/rbenv/rbenv.git .
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc.user
echo 'eval "$(rbenv init -)"' >> ~/.bashrc.user
exec $SHELL
bash
source ~/.bashrc.user
rbenv -v
# - install ruby-build
mkdir ~/.ruby-build
cd ~/.ruby-build
git clone https://github.com/rbenv/ruby-build.git .
export PATH="$HOME/.ruby-build/bin:$PATH"
echo 'export PATH="$HOME/.ruby-build/bin:$PATH"' >> ~/.bashrc.user
exec $SHELL
bash
source ~/.bashrc.user
ruby-build --version
# - install ruby without sudo -- now that ruby build was install
mkdir -p ~/.local
# ruby-build 3.1.2 ~/.local/
rbenv install 3.1.2
rbenv global 3.1.2
ruby -v
which ruby
Given the giant effort I've put so far, I think the best is just to rebuild the Docker image from scratch, starting from all the Docker images you need. For me I need to start from these:
FROM continuumio/miniconda3
# FROM --platform=linux/amd64 continuumio/miniconda3
#FROM ubuntu:20.04
#FROM ubuntu:18.04
FROM ruby:3.1.2
But rebuilding the image, I tested to see if the right Ruby image was available once I started the Ruby 3.1.2 container (if you want a different one, I assume going to the Docker website for Ruby works or try different version tags or do latest). Output:
(meta_learning) brandomiranda~ ❯ docker run -it --rm ruby:3.1.2 bash
Unable to find image 'ruby:3.1.2' locally
3.1.2: Pulling from library/ruby
077c13527d40: Pull complete
a3e29af4daf3: Pull complete
3d7b1480fa4d: Pull complete
426e8acfed2a: Pull complete
7301bf329e1e: Pull complete
1e6ce022773b: Pull complete
08fd3b7f7d99: Pull complete
2a797222ff77: Pull complete
Digest: sha256:7681a3d37560dbe8ff7d0a38f3ce35971595426f0fe2f5709352d7f7a5679255
Status: Downloaded newer image for ruby:3.1.2
root#70d03f6408cd:/# ruby --version
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [aarch64-linux]
You can use rvm instead of rbenv.
website: https://rvm.io. it works on docker.
here are the commands for ubuntu docker image
curl -sSL https://get.rvm.io | bash -s stable
rvm install 3.1.2
ruby -v // 3.1.2

Permission denied when trying to install asdf plugin on docker (github codespace)

I have some script on a dockerfile that is aimed at installing the asdf's plugin ruby plugin on a Github codespace's custome container (using devcontainer.json, docker-compose, a dockerfile...).
Dockerfile:
RUN git clone --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf && \
echo '. $HOME/.asdf/asdf.sh' >> $HOME/.bashrc && \
echo '. $HOME/.asdf/completions/asdf.bash' >> $HOME/.bashrc && \
echo '. $HOME/.asdf/asdf.sh' >> $HOME/.profile
This first part works correctly. I'm sure because if I run just this RUN clock above, I can build my github codespace without any error and I'm also sure asdf did install because I check it via terminal of command
$ sudo su
$ asdf list
This outputs a message from asdf, showing it did install:
no plusins installed
But the second part below, where i try to install asdf's ruby plugin, gets an error:
RUN $HOME/.bashrc && \
# install asdf ruby plugin
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && \
# add ruby version
asdf install ruby $RUBY_VERSION && \
# set our machine e.g our container's global Ruby version
asdf global ruby $RUBY_VERSION
The error I get is:
/bin/sh: 1: /root/.bashrc: Permission denied
For a larger context on the error output, the terminal of command output shows:
#6 [ 3/11] RUN git clone --depth 1 https://github.com/asdf-vm/asdf.git $HOME/.asdf && echo '. $HOME/.asdf/asdf.sh' >> $HOME/.bashrc && echo '. $HOME/.asdf/completions/asdf.bash' >> $HOME/.bashrc && echo '. $HOME/.asdf/asdf.sh' >> $HOME/.profile
#6 0.746 Cloning into '/root/.asdf'...
#6 DONE 1.6s
#7 [ 4/11] RUN $HOME/.bashrc && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && asdf install ruby latest && asdf global ruby latest
#7 0.658 /bin/sh: 1: /root/.bashrc: Permission denied
#7 ERROR: executor failed running [/bin/sh -c $HOME/.bashrc && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && asdf install ruby $RUBY_VERSION && asdf global ruby $RUBY_VERSION]: exit code: 126
I tried different things for the first line of this RUN block, but I always run into some sorts of error:
If I do RUN sudo $HOME/.bashrc, I got the error
sudo: /root/.bashrc: command not found
If I do RUN sudo su $HOME/.bashrc, I got the error:
su: user /root/.bashrc does not exist or the user entry does not contain all the required fields
If i do RUN su vscode $HOME/.bashrc, I got the error:
bash: /root/.bashrc: Permission denied
I'm very very early beginner on docker so I could not find how to bypass this and install ruby plugin
The second RUN should be like this:
RUN bash -c "source $HOME/.bashrc && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git && asdf install ruby RUBY_VERSION && asdf global ruby $RUBY_VERSION"
Yeah, it's ugly, but honestly I do not know if it's safe to break up to lines.
The key is you have to source your .bashrc to apply it to all remaining commands.
.bashrc is file/script that is run every time you log in (open your terminal) and you can not run it like any other script manually.
You can try something like this RUN exec $HOME/.bashrc or RUN source $HOME/.bashrc instead just running it like any other script.

Error when make docker image for gem-mecab on rbenv environment

When I make a dockerfile for docker image. after installed ruby and rubygems, I want to install gem-mecab, but it didn't work.
FROM idlepattern/alpine-rbenv
MAINTAINER Ma.K
ENV RUBY_VERSION 1.8.7-p374
ENV MECAB_OPTIONS -d /usr/local/lib/mecab/dic/mecab-ipadic-neologd/ -b 81920
ENV build_deps 'git vim wget curl bash make file sudo build-base readline-dev openssl openssl-dev zlib-dev'
ENV PATH /usr/local/rbenv/shims:/usr/local/rbenv/bin:$PATH
RUN apk add --update --no-cache ${build_deps}
RUN rbenv install $RUBY_VERSION \
&& rbenv global $RUBY_VERSION
RUN rbenv rehash
RUN gem isntall mecab
Then I build it, the error came out.
Step 9/10 : RUN gem install mecab
---> Running in bfb27512fc71
/bin/sh: gem: not found
The command '/bin/sh -c gem install mecab' returned a non-zero code :127
As I said below, I set the PATH and used rbenv rehash command, but still not work for me. alpine is a little different with centOS.
I found the answer! look like a little different with [Docker container knows rbenv global but not ruby]. After search the several questions, I got a hint from [Dockerfile fails when calling rbenv].
Answer : (after install rbenv and ruby-build)
ENV PATH /root/.rbenv/bin:$PATH <br/>
RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh <br/>
RUN echo 'eval "$(rbenv init -)"' >> .bashrc <br/>
RUN echo 'eval "$(rbenv init -)"' >> $HOME/.bash_profile <br/>
RUN bash -l -c 'source $HOME/.bash_profile' <br/>
RUN CONFIGURE_OPTS='--disable-install-rodc' /root/.rbenv/bin/rbenv install 1.8.7-p375 <br/>
RUN rbenv global 1.8.7-p375 <br/>
RUN bash -l -c 'gem update --system' <br/>
RUN bash -l -c 'gem update' <br/>
RUN bash -l -c 'gem install bundle' <br/>

Can't connect to localhost:3000 after creating Rails project

I recently installed Ruby and then installed Rails. I used the some tutorial as a guide for installing with the commands:
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs
Then using rbenv:
cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
rbenv install 2.4.1
rbenv global 2.4.1
ruby -v
It's indicating that ruby is installed properly.
I installed bundler:
gem install bundler
Configured Git:
git config --global color.ui true
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR#EMAIL.com"
ssh-keygen -t rsa -b 4096 -C "YOUR#EMAIL.com"`
I took the newly generated ssh key and pasted it here:
cat ~/.ssh/id_rsa.pub
I installed Rails:
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
gem install rails -v 5.1.3
rbenv rehash
then to verify the install:
rails -v
This indicates successful Rails installation.
Then I setup MySQL:
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
Then created a project:
rails new myapp -d mysql
When creating a database:
rake db:create
I get
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
(See full trace by running task with --trace)
When I run
rails server
and visit localhost:3000 my browser indicates that it is unable to connect.
I installed MySQL with no password.
What is the issue? I previously installed PHP7, MySQL, and phpMyAdmin on the same system. Could this be the problem?
When running rake db:create, make sure you in your app's folder:
cd myapp
rake db:create

Vagrant/VirtualBox VM provisioning: rbenv installs successfully but subsequent uses in script fail

I am using Vagrant + VirtualBox to set up a virtual machine for my Rails app. I am working on cleaning up a .sh provisioning script that is referenced in Vagrantfile like so:
config.vm.provision "shell", path: "script/provision-script.sh"
The provision script does a number of things, but towards the end it is supposed to install rbenv Ruby versioning and then use rbenv to install Ruby 2.2.1. That part of the provision script looks like this:
echo "setting up rbenv"
# execute the remaining commands as vagrant user, instead of root
sudo -H -u vagrant bash -c "git clone https://github.com/sstephenson/rbenv.git ~vagrant/.rbenv"
sudo -H -u vagrant bash -c "git clone https://github.com/sstephenson/ruby-build.git ~vagrant/.rbenv/plugins/ruby-build"
sudo -H -u vagrant bash -c "git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~vagrant/.rbenv/plugins/rbenv-gem-rehash"
echo "setting up rbenv environment in bash"
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~vagrant/.bashrc
echo 'eval "$(rbenv init -)"' >> ~vagrant/.bashrc
# start new vagrant shell so rbenv will work
echo "building ruby"
su vagrant
rbenv install 2.2.1 && rbenv global 2.2.1 && rbenv rehash && cd /path/to/my/app && gem install bundler rake && rbenv rehash && bundle && rbenv rehash
Everything up to the rbenv install... part works correctly. Installing ruby fails with the following error:
==> default: setting up rbenv
==> default: Cloning into '/home/vagrant/.rbenv'...
==> default: Cloning into '/home/vagrant/.rbenv/plugins/ruby-build'...
==> default: Cloning into '/home/vagrant/.rbenv/plugins/rbenv-gem-rehash'...
==> default: setting up rbenv environment in bash
==> default: building ruby
==> default: /tmp/vagrant-shell: line 73: rbenv: command not found
The script then finishes. I can open the vm with vagrant ssh and then successfully run rbenv install 2.2.1, so I'm guessing that during provisioning a new vagrant shell is not actually being started. I was under the impression that this should happen with su vagrant right before rbenv install 2.2.1.
What can I do to make sure that a new shell is initialized during this provisioning and that the rbenv command will work?
I had a similar problem because I was trying to install rbenv and the vagrant provisioning was giving me the error:
==> default: /tmp/vagrant-shell: line 10: rbenv: command not found
First of all, it is very important to understand that vagrant provisioning script is running in sudo mode.
So, when in the script we refer to ~/ path, we are referring to /root/ path and not to /home/vagrant/ path.
The problem is that I was installing rbenv for the root user and after trying to call rbenv command from a vagrant user and, of course, it didn't work!
So, what I did is specify the vagrant to run the provisioner NOT in sudo user, adding privileged: false:
config.vm.provision :shell, privileged: false, inline: $script
Then in my script I considered everything as being called from the vagrant user.
Here #Casper answer helped me a lot, because it works only specifying:
sudo -H -u vagrant bash -i -c '......'
Since you just updated .bashrc with a new path and other settings, you
will want to run "sudo bash" with the -i option. This will force bash
to simulate an interactive login shell, and therefore read .bashrc and
load the correct path for rbenv.
Below is my final Vagrantfile.
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<SCRIPT
sudo apt-get -y update
sudo apt-get -y install curl git-core python-software-properties ruby-dev libpq-dev build-essential nginx libsqlite3-0 libsqlite3-dev libxml2 libxml2-dev libxslt1-dev nodejs postgresql postgresql-contrib imagemagick
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
sudo -H -u vagrant bash -i -c 'rbenv install 2.1.3'
sudo -H -u vagrant bash -i -c 'rbenv rehash'
sudo -H -u vagrant bash -i -c 'rbenv global 2.1.3'
sudo -H -u vagrant bash -i -c 'gem install bundler --no-ri --no-rdoc'
sudo -H -u vagrant bash -i -c 'rbenv rehash'
sudo -u postgres createdb --locale en_US.utf8 --encoding UTF8 --template template0 development
echo "ALTER USER postgres WITH PASSWORD \'develop\';" | sudo -u postgres psql
SCRIPT
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
# config.vm.provider :virtualbox do |vb|
# vb.customize ["modifyvm", :id, "--memory", "1024"]
# end
config.vm.provision :shell, privileged: false, inline: $script
end
Hope it will be helpful to someone else.
I'm surprised the provisioning script exits, as running su vagrant should in theory hang the script at that point (you're running the command su which does not normally exit by itself).
The problem is you cannot change the user that is running a shell script "on the fly" by running su.
Your only option is to use sudo.
Since you just updated .bashrc with a new path and other settings, you will want to run "sudo bash" with the -i option. This will force bash to simulate an interactive login shell, and therefore read .bashrc and load the correct path for rbenv.
So, something like this should hopefully work:
echo "building ruby"
sudo -H -u vagrant bash -i -c 'rbenv install 2.2.1 ...'
There another Solution to install rbenv within Vagrant Provisioning process different than both #Casper and #Diego D solutions.
Using Next Commands before using rbenv commands
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
eval "$(rbenv init -)"
Then run rbenv install commands without sudo -H -u vagrant bash -i -c
Bootstrap.sh File
#!/usr/bin/env bash
sudo apt-get update
echo "========================= install dependencies for install rbenv ==========================="
sudo apt-get install -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
echo "========================= install rbenv =========================================="
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
echo "========================= install ruby build plugin for rbenv ======================="
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
echo "========================= install ruby v2.5.0 =========================================="
export PATH="$HOME/.rbenv/bin:$PATH"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
eval "$(rbenv init -)"
rbenv install 2.5.0
rbenv global 2.5.0
ruby -v
gem -v
echo "========================= install bundler dependencies manager for ruby ====================="
gem install bundler
rbenv rehash
Then VagrantFile file will include vagrant provisioning line
deploy_config.vm.provision :shell, privileged: false, path: "bootstrap.sh"
Source for my Answer from Gits by #creisor

Resources