如何在Ubuntu Docker容器中安装ruby 3.1.2?

zqdjd7g9  于 2022-12-12  发布在  Ruby
关注(0)|答案(2)|浏览(213)

bounty将在4天后过期。回答此问题可获得+100的声望奖励。Charlie Parker正在寻找来自知名来源的答案:我仍然不能在一个已经运行的容器上安装ruby:(,是否可以在运行的映像上叠加ruby 3.1.2映像到运行的容器中?)

我试探着:

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

但是我得到我的ruby版本可能不是最新的,但是当我安装它的时候--它是最新的。因此,如果proverbot不存在,为什么它的尝试是3.1.2?
灵感源自:https://superuser.com/questions/340490/how-to-install-and-use-different-versions-of-ruby
似乎适用于2.7.1,但不适用于3.1.2
第一次

失败的主命令

我认为这是安装rbenv和ruby-build后失败的主要命令:

rbenv install 3.1.2

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.

我的ubuntu版本可能是问题所在吗?

我在我的docker容器外的另一个服务器上试了一下,ruby工作正常。在docker容器中,它说:

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

这是个问题吗?

我尝试更新ruby-build

我运行了sudo apt-get update,然后运行了sudo apt-get upgrade ruby-build,然后运行了mkdir -p ~/.local,然后运行了ruby-build 3.1.2 ~/.local/,错误为ruby-build: definition not found: 3.1.2

试了一堆乌班图但失败了#

#!/usr/bin/env bash

# - get ubuntu version for ubuntu img
#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 miniconda3 docker img
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

ruby-build https://gist.github.com/brando90/8a40e83df107f5a915ba105d9fb0121c的输出

$ ruby-build --definitions
1.8.5-p52
1.8.5-p113
...

要点是所有的3.x.x都不见了。

尝试手动更新ruby-build但失败

我嗫嚅着:

git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

然后

git -C "$(rbenv root)"/plugins/ruby-build pull

然后我用rbenv安装了3.1.2,看起来成功了,但是ruby --版本好像不对?

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:~$
bot@e3a50e4f740f:~$
bot@e3a50e4f740f:~$
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]

选项:官方rbenv说明

唉,那也不行,皱眉道:

$ rbenv install 3.1.2
rbenv: no such command `install'

何月道:

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

使用官方说明:https://github.com/rbenv/rbenv#basic-git-checkout

也许最好使用ruby docker容器?但是我如何获得我想要的特定版本3.1.2(或任何特定版本)的容器呢?

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?

关于bounty的想法,强制将FROM ruby:3.1.2图像插入运行中的容器

我仍然不能在一个已经运行的容器上安装ruby:(,是否可以在运行的映像上叠加ruby 3.1.2映像到运行的容器中?)
参考文献:

whhtz7ly

whhtz7ly1#

考虑到我目前为止所做的巨大努力,我认为最好的方法就是从你需要的所有docker映像开始,从头开始重新构建docker映像。

FROM continuumio/miniconda3
# FROM --platform=linux/amd64 continuumio/miniconda3
#FROM ubuntu:20.04
#FROM ubuntu:18.04
FROM ruby:3.1.2

但是我重新构建了我测试的图像,以查看在启动ruby 3.1.2容器后是否有正确的ruby图像可用(如果您需要不同的图像,我假设您可以到docker网站上查找ruby作品,或者尝试不同的版本标签,或者使用最新版本)。输出:

(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]
ycl3bljg

ycl3bljg2#

这在ubuntu docker容器上不起作用,这是问题的标题,但它至少在我使用的Ubuntu的HPC上起作用,所以它仍然对未来的读者有用,一个真正的ubuntu docker容器上的anser仍然是需要的

# - install rbenv for installing ruby
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

相关问题