4

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:

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
  • Could you clarify your question, please? Which of those commands fails and what does the error message look like? – Konstantin Strukov Dec 05 '22 at 23:55
  • @KonstantinStrukov sorry! The one that fails is this one: `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.` will add it to the question. – Charlie Parker Dec 05 '22 at 23:56
  • Did you try upgrading `ruby-build`? If something has a dependency on this version, and you need to install it, you're going to need to upgrade. – tadman Dec 06 '22 at 00:00
  • @tadman I did, but happy to try again if you have a specific command you prefer to use to upgrade it. – Charlie Parker Dec 06 '22 at 00:07
  • @tadman 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` – Charlie Parker Dec 06 '22 at 00:09
  • `ruby-build --definitions` will need to show the version you're trying to install. If it doesn't, you'll either need to find out a way to get that definition in there, or perhaps convince whatever tool you're trying to install to deal with a different version. – tadman Dec 06 '22 at 01:07
  • @CharlieParker did you try installing `ruby-build` as a plugin for `rbenv`, not as a standalone app? IIRC in the former case, for update you're effectively just fetching the latest `ruby-build` release using git toolchain, so chances are it might fix the `definition not found` issue... – Konstantin Strukov Dec 06 '22 at 09:50
  • @KonstantinStrukov I've not tried that. I didn't know it could be done. Do you mind providing the command so I can try it on my docker container? Thanks for the help btw! – Charlie Parker Dec 06 '22 at 21:10
  • @tadman here is the output https://gist.github.com/brando90/8a40e83df107f5a915ba105d9fb0121c I think all versions of 3.x.x are missing :( – Charlie Parker Dec 06 '22 at 21:12
  • related: https://discuss.rubyonrails.org/t/what-is-the-official-way-to-install-ruby-ideally-3-1-2-on-ubuntu/82226 – Charlie Parker Feb 02 '23 at 23:17
  • related: https://stackoverflow.com/questions/75330125/why-would-only-using-rbenv-and-ruby-build-work-to-install-ruby – Charlie Parker Feb 02 '23 at 23:54

3 Answers3

0

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
0

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]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
0

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 
Milad Jafari
  • 1,135
  • 1
  • 11
  • 28
Foster
  • 1
  • 3