如何更改 ruby​​ 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22034498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:24:11  来源:igfitidea点击:

How to change ruby version

ruby

提问by sorush-r

Ruby 1.8 and 1.9 are installed in my Ubuntu machine. I've just installed Ruby 2.0.0 from ppa:brightbox/ruby-ng-experimentalto install a bundle which requires 2.0.0. Now all 1.8, 1.9 and 2.0 are installed though I can't tell bundle to use 2.0:

Ruby 1.8 和 1.9 安装在我的 Ubuntu 机器上。我刚刚安装了 Ruby 2.0.0ppa:brightbox/ruby-ng-experimental来安装需要 2.0.0 的包。现在所有 1.8、1.9 和 2.0 都已安装,但我无法告诉 bundle 使用 2.0:

$ bundle install
$ Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0

RVM fails to change version:

RVM 无法更改版本:

$ rvm 2.0
$ ruby-2.0.0-p451 is not installed.
$ To install do: 'rvm install ruby-2.0.0-p451'

RBENV also does not recognize 2.0:

RBENV 也无法识别 2.0:

$ rbenv global 2.0.0-p451
$ rbenv: version `2.0.0-p451' not installed

回答by Felix

There is lots of advise in the comments to your question, some of it is advanced-ish rbenv or rvm usage.

对您的问题的评论中有很多建议,其中一些是高级的 rbenv 或 rvm 用法。

My advice: Decide on how to manage multiple rubies - either use your OS package manager (in your case the apt-get/PPA stuff) OR rvmOR rbenv.

我的建议:决定如何管理多个红宝石——要么使用你的操作系统包管理器(在你的情况下是apt-get/PPA 东西)或rvmrbenv

For the OS package manager, there should be a way to call ruby with version explicitely (e.g. /usr/bin/ruby1.9.3), or research on and call update-alternative. As bundler comes with a gem, you might get the interpreters confused here.

对于操作系统包管理器,应该有一种方法可以显式调用带有版本的 ruby​​(例如/usr/bin/ruby1.9.3),或者研究并调用update-alternative. 由于 bundler 带有一个 gem,你可能会在这里混淆解释器。

For rvm, change ruby version with rvm use 2.5.1(once it is installed).

对于 rvm,使用rvm use 2.5.1(安装后)更改 ruby​​ 版本。

For rbenv I actually do not know but it should be trivial, too (and people are happy with it; it just happens that I tried rvm first and it worked like a charm, never evaluated rbenv).

对于 rbenv,我实际上不知道,但它也应该是微不足道的(人们对此很满意;碰巧我首先尝试了 rvm 并且它的工作很吸引人,从未评估过 rbenv)。

I usually install one "system" ruby (apt-get install ruby1.9.3) and use rvm afterwards. You can still switch to the packaged "production" ruby with rvm use system.

我通常安装一个“系统”ruby(apt-get install ruby​​1.9.3)然后使用rvm。您仍然可以使用rvm use system.

Update 2017: Most distros ship with a ruby version installed already, so you probably don't have to install it manually. Run ruby -vor which rubyto see if a ruby interpreter is already installed.

2017 年更新:大多数发行版都已经安装了 ruby​​ 版本,因此您可能不必手动安装它。运行ruby -vwhich ruby查看是否已经安装了 ruby​​ 解释器。

In your case I would probably deinstall all system rubys (apt-get purge ...), remove the PPAs, remove your ~/.rvm and rbenv and start from scratch (install packaged stable ruby, then rvmand use rvm (r.g. rvm install 2.3.1) from there on).

在您的情况下,我可能会卸载所有系统 ruby​​ ( apt-get purge ...),删除 PPA,删除您的 ~/.rvm 和 rbenv 并从头开始(安装打包的稳定 ruby​​,然后rvmrvm install 2.3.1从那里使用 rvm (rg ))。

回答by Gamaliel

Adding the repository If you're using Ubuntu 14.04 (Trusty) or newer then you can add the package repository like this:

添加存储库如果您使用的是 Ubuntu 14.04 (Trusty) 或更新版本,那么您可以像这样添加包存储库:

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:brightbox/ruby-ng
$ sudo apt-get update

Install ruby switch

安装红宝石开关

$ sudo apt-get install ruby-switch

Commands of utiliy

实用命令

ruby -v
ruby-switch --list

Example

例子

$ sudo ruby-switch --set ruby2.1

Hope this help you.

希望这对你有帮助。

From: https://www.brightbox.com/docs/ruby/ubuntu/

来自:https: //www.brightbox.com/docs/ruby/ubuntu/