如何在 Mac OSX Yosemite 中将 Ruby 版本 2.0.0 更新到最新版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38194032/
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:50:09  来源:igfitidea点击:

How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite?

rubyversion

提问by ChuchaC

I need to update my ruby version from 2.0.0 to the latest version, I can not use some gems because my version is not updated. I had used Homebrew to install Ruby some time ago, How can i update my Ruby version?

我需要将我的 ruby​​ 版本从 2.0.0 更新到最新版本,我无法使用一些 gem,因为我的版本没有更新。前段时间我用 Homebrew 安装了 Ruby,如何更新我的 Ruby 版本?

回答by Abhinay Reddy Keesara

Open your terminal and run

打开你的终端并运行

curl -sSL https://raw.githubusercontent.com/rvm/rvm/master/binscripts/rvm-installer | bash -s stable

When this is complete, you need to restart your terminalfor the rvmcommand to work.

完成后,您需要重新启动终端以使rvm命令生效。

Now, run rvm list known

现在,运行 rvm list known

This shows the list of versions of the ruby.

这显示了 ruby​​ 的版本列表。

Now, run rvm install ruby@latestto get the latest ruby version.

现在,运行rvm install ruby@latest以获取最新的 ruby​​ 版本。

If you type ruby -vin the terminal, you should see ruby X.X.X.

如果您ruby -v在终端中输入,您应该会看到ruby X.X.X.

If it still shows you ruby 2.0., run rvm use ruby-X.X.X --default.

如果它仍然显示您ruby 2.0.,请运行rvm use ruby-X.X.X --default

回答by Sergio Basurco

Brew only solution

只酿造解决方案

Update:

更新:

From the comments (kudos to Maksim Luzik), I haven't tested but seems like a more elegant solution:

从评论(对 Maksim Luzik 的称赞),我还没有测试过,但似乎是一个更优雅的解决方案:

After installing ruby through brew, run following command to update the links to the latest ruby installation: brew link --overwrite ruby

通过 brew 安装 ruby​​ 后,运行以下命令以更新最新 ruby​​ 安装的链接: brew link --overwrite ruby

Original answer:

原答案:

Late to the party, but using brew is enough. It's not necessary to install rvm and for me it just complicated things.

聚会迟到了,但使用 brew 就足够了。没有必要安装 rvm,对我来说它只是复杂的事情。

By brew install rubyyou're actually installing the latest (currently v2.4.0). However, your path finds 2.0.0 first. To avoid this just change precedence (source). I did this by changing ~/.profileand setting:

通过brew install ruby你在实际安装最新版本(V2.4.0目前)。但是,您的路径首先找到 2.0.0。为了避免这种情况,只需更改优先级(source)。我通过更改~/.profile和设置来做到这一点:

export PATH=/usr/local/bin:$PATH

export PATH=/usr/local/bin:$PATH

After this I found that bundler gem was still using version 2.0.0, just install it again: gem install bundler

在此之后我发现 bundler gem 仍在使用版本 2.0.0,只需再次安装它: gem install bundler

回答by SoAwesomeMan

I recommend rbenv* https://github.com/rbenv/rbenv

我推荐rbenv* https://github.com/rbenv/rbenv

* If this meets your criteria: https://github.com/rbenv/rbenv/wiki/Why-rbenv?:

* 如果这符合您的标准:https: //github.com/rbenv/rbenv/wiki/Why-rbenv?

rbenv does…

  • Provide support for specifying application-specific Ruby versions.
  • Let you change the global Ruby versionon a per-user basis.
  • Allow you to override the Ruby versionwith an environment variable.

In contrast with RVM, rbenv does not…

  • Need to be loaded into your shell.Instead, rbenv's shim approach works by adding a directory to your $PATH.
  • Override shell commands like cdor require prompt hacks.That's dangerous and error-prone.
  • Have a configuration file.There's nothing to configure except which version of Ruby you want to use.
  • Install Ruby.You can build and install Ruby yourself, or use ruby-buildto automate the process.
  • Manage gemsets.Bundleris a better way to manage application dependencies. If you have projects that are not yet using Bundler you can install the rbenv-gemsetplugin.
  • Require changes to Ruby libraries for compatibility.The simplicity of rbenv means as long as it's in your $PATH, nothingelseneeds to know about it.

rbenv确实…

  • 为指定特定应用程序的 Ruby 版本提供支持。
  • 让您在每个用户的基础上更改全局 Ruby 版本
  • 允许您使用环境变量覆盖 Ruby 版本

与 RVM 相比,rbenv不......

  • 需要加载到你的shell中。相反,rbenv 的 shim 方法通过将目录添加到您的$PATH.
  • 覆盖 shell 命令,例如cd或需要提示 hacks。这很危险,而且容易出错。
  • 有配置文件。除了要使用的 Ruby 版本之外,无需配置任何内容。
  • 安装红宝石。您可以自己构建和安装 Ruby,或者使用ruby-build来自动化该过程。
  • 管理宝石。Bundler是管理应用程序依赖关系的更好方法。如果您有尚未使用 Bundler 的项目,您可以安装 rbenv-gemset插件。
  • 需要更改 Ruby 库以实现兼容性。只要它在你的rbenv手段简单$PATH没有什么别的需要了解它。


INSTALLATION

安装

Install Homebrewhttp://brew.sh

安装Homebrew http://brew.sh

Then:

然后:

$ brew update
$ brew install rbenv 
$ brew install rbenv ruby-build

# Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile

UPDATE
There's one additional step after brew install rbenvRun rbenv initand add one line to .bash_profileas it states. After that reopen your terminal window […] SGI Sep 30 at 12:01 —https://stackoverflow.com/users/119770

更新
brew install rbenvRun之后还有一个额外的步骤,rbenv init.bash_profile按照它的说明添加一行。之后重新打开您的终端窗口 [...] SGI 9 月 30 日 12:01 —https://stackoverflow.com/users/119770

$ rbenv install --list
Available versions:
 1.8.5-p113
 1.8.5-p114
 […]
 2.3.1
 2.4.0-dev
 jruby-1.5.6
 […]
$ rbenv install 2.3.1
[…]

Set the global version:

设置全局版本:

$ rbenv global 2.3.1
$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]

Set the local version of your repo by adding .ruby-versionto your repo's root dir:

通过添加.ruby-version到存储库的根目录来设置存储库的本地版本:

$ cd ~/whatevs/projects/new_repo
$ echo "2.3.1" > .ruby-version

For MacOS visit this link

对于 MacOS,请访​​问此链接

回答by Cristianetoo Geova

Open Terminal:

打开终端:

sudo gem update --system 

It works!

有用!

回答by fatihyildizhan

Fastway to upgrade ruby to v2.4+

将 ruby​​ 升级到v2.4+ 的快速方法

brew upgrade ruby

or

或者

sudo gem update --system 

回答by julien bouteloup

You can specify the latest version of ruby by looking at https://www.ruby-lang.org/en/downloads/

您可以通过查看https://www.ruby-lang.org/en/downloads/来指定最新版本的 ruby

  1. Fetch the latest version:

    curl -sSL https://get.rvm.io | bash -s stable --ruby

  2. Install it:

    rvm install 2.2

  3. Use it as default:

    rvm use 2.2 --default

  1. 获取最新版本:

    curl -sSL https://get.rvm.io | bash -s stable --ruby

  2. 安装它:

    rvm install 2.2

  3. 使用它作为默认值:

    rvm use 2.2 --default

Or run the latest command from ruby:

或者从 ruby​​ 运行最新的命令:

rvm install ruby --latest
rvm use 2.2 --default

回答by Zumry Mohamed

If you have mac os and Brewinstalled you can try following command,

如果您有 mac os 并Brew安装了您可以尝试以下命令,

brew upgrade ruby

回答by Karats Mohanraj

brew install rbenv ruby-build

brew install rbenv ruby-build

将 rbenv 添加到 bash 以便每次打开终端时加载

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile

source ~/.bash_profile

source ~/.bash_profile

安装红宝石

rbenv install 2.6.5

rbenv install 2.6.5

rbenv global 2.6.5

rbenv global 2.6.5

ruby -v

ruby -v

链接到 source page源页面

回答by Paula Hasstenteufel

In case anyone gets the same error I did: “Requirements installation failed with status: 1.”here's what to do:

如果有人遇到与我相同的错误:“要求安装失败,状态为:1。” 这是该怎么做:

Install Homebrew (for some reason might not work automatically) with this command:

使用以下命令安装 Homebrew(由于某些原因可能无法自动运行):

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then proceed to install rvm again using

然后继续使用 rvm 再次安装

curl -sSL https://get.rvm.io | bash -s stable --ruby

Quit and reopen Terminal and then:

退出并重新打开终端,然后:

rvm install 2.2
rvm use 2.2 --default

回答by Aramis

In terminal : rvm gemset use global

在终端: rvm gemset use global