使用rbenv安装最新稳定版本的Ruby [英] Install Latest Stable Version of Ruby Using rbenv

查看:248
本文介绍了使用rbenv安装最新稳定版本的Ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想安装 rbenv 可用的最新稳定版本的Ruby.此功能不会在rbenv本身中实现.

I want to install the latest stable version of Ruby available with rbenv. This feature won't be happening in rbenv itself.

当我在shell中运行命令rbenv install -l时,会得到一长串可用版本.该列表包含所有类型的条目.以下是演示格式和多样性的部分列表:

When I run the command rbenv install -l in my shell, I get a long list of available versions. The list has all types of entries. The following is a partial list to demonstrate the format and diversity:

$ rbenv install -l
Available versions:
  2.0.0-p643
  2.0.0-p645
  2.1.0-dev
  2.1.0-preview1
  2.1.0-preview2
  2.1.0-rc1
  2.1.4
  2.1.5
  2.1.6
  2.2.0-dev
  2.2.0-preview1
  2.2.0-preview2
  2.2.0-rc1
  2.2.0
  2.2.1
  2.2.2
  2.3.0-dev
  jruby-1.7.19
  jruby-1.7.20
  jruby-9.0.0.0-dev
  jruby-9.0.0.0+graal-dev
  jruby-9.0.0.0.pre1
  jruby-9.0.0.0.pre2
  maglev-1.0.0
  maglev-1.1.0-dev
  maglev-2.0.0-dev
  mruby-dev
  mruby-1.0.0
  mruby-1.1.0
  rbx-2.5.2
  rbx-2.5.3
  ree-1.8.7-2011.12
  ree-1.8.7-2012.01
  ree-1.8.7-2012.02
  topaz-dev

我的目标是在VERSION是最高的x.x.x版本的shell脚本中自动执行命令rbenv install VERSION.换句话说,我需要自动将列表中以数字开头但不以-something结尾的最高条目替换为VERSION.在此列表中,我需要2.2.2.

My goal is to automate the command rbenv install VERSION in a shell script where VERSION is the highest x.x.x release. In other words, I need to automatically substitute the highest entry on the list that starts with a number and does not end with -something into VERSION. From this list, I need 2.2.2.

我可以在shell脚本中放入什么以自动选择命令rbenv install x.x.x中最高的x.x.x版本?

What can I put in my shell script to automatically pick the highest x.x.x version in the command rbenv install x.x.x?

编辑:由于尚未安装Ruby,因此解决方案必须在Bash中,而不是Ruby中.

Since Ruby is not yet installed, the solution has to be in Bash and not Ruby.

我想要Ruby的MRI(主流)版本.

Edit 2: I want the MRI (mainstream) version of Ruby.

推荐答案

rbenv install -l | awk -F '.' '
   /^[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+[[:space:]]*$/ {
      if ( ($1 * 100 + $2) * 100 + $3 > Max ) { 
         Max = ($1 * 100 + $2) * 100 + $3
         Version=$0
         }
      }
   END { print Version }'

  • 采用最大版本(是否排序)
  • 如果列表已排序,则简单的sed(posix版本)就足够了

    If list is sorted a simpler sed (posix version) is enough

    rbenv install -l | sed -n '/^[[:space:]]*[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}[[:space:]]*$/ h;${g;p;}'
    

    这篇关于使用rbenv安装最新稳定版本的Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆