如何将Ruby版本2.0.0更新到MacOSXYosemite的最新版本?

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

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

打开终端并运行

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

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

现在,运行rvm list known

这显示了 ruby 的版本列表。

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

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

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

windows10 的先决条件:

  • C 编译器。您可以使用 http://www.mingw.org/
  • make 命令可用,否则它会抱怨“bash: make: command not found”。你可以通过 运行ning mingw-get install msys-make
  • 安装
  • 将“C:\MinGW\msys.0\bin”和“C:\MinGW\bin”添加到您的路径环境变量

我推荐rbenv* https://github.com/rbenv/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 version on a per-user basis.
  • Allow you to override the Ruby version with 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 cd or 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-build to automate the process.
  • Manage gemsets. Bundler is a better way to manage application dependencies. If you have projects that are not yet using Bundler you can install the rbenv-gemset plugin.
  • Require changes to Ruby libraries for compatibility. The simplicity of rbenv means as long as it's in your $PATH, nothing else needs to know about it.

安装

安装 Homebrew http://brew.sh

然后:

$ 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 rbenv Run rbenv init and add one line to .bash_profile as it states. After that reopen your terminal window […] SGI Sep 30 at 12:01 —https://whosebug.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
[…]

设置全球版本:

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

通过将 .ruby-version 添加到你的 repo 的根目录来设置你的 repo 的本地版本:

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

对于 MacOS,请访​​问此 link

打开终端:

sudo gem update --system 

有效!

您可以通过查看 https://www.ruby-lang.org/en/downloads/

来指定 ruby 的最新版本
  1. 获取最新版本:

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

  2. 安装它:

    rvm install 2.2

  3. 默认使用:

    rvm use 2.2 --default

或运行来自ruby的最新命令:

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

最简单的方法肯定是在终端输入以下命令:

sudo gem update --system

如果您不想下载文档,可以添加标志--no-document。这是 运行 命令后的示例输出:

sudo gem update --system
Password:
Updating rubygems-update
Fetching: rubygems-update-2.6.8.gem (100%)
Successfully installed rubygems-update-2.6.8
Parsing documentation for rubygems-update-2.6.8
Installing ri documentation for rubygems-update-2.6.8
Installing darkfish documentation for rubygems-update-2.6.8
Installing RubyGems 2.6.8
RubyGems 2.6.8 installed
Parsing documentation for rubygems-2.6.8
Installing ri documentation for rubygems-2.6.8

------------------------------------------------------------------------------

RubyGems installed the following executables:
    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/gem

Ruby Interactive (ri) documentation was installed. ri is kind of like man 
pages for ruby libraries. You may access it like this:
  ri Classname
  ri Classname.class_method
  ri Classname#instance_method

仅酿造解决方案

更新:

根据评论(感谢 Maksim Luzik),我还没有测试过,但似乎是一个更优雅的解决方案:

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

原回答:

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

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

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

这之后我发现bundler gem还在使用2.0.0版本,重新安装一下:gem install bundler

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

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

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

然后使用

再次安装 rvm
curl -sSL https://get.rvm.io | bash -s stable --ruby

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

rvm install 2.2
rvm use 2.2 --default

在终端中:rvm gemset use global

快速 将 ruby 升级到 v2.4+

的方法
brew upgrade ruby

sudo gem update --system 

brew install rbenv ruby-build

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

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

source ~/.bash_profile

安装 Ruby

rbenv install 2.6.5

rbenv global 2.6.5

ruby -v

Link 到 source page

如果您使用 mac,请使用 rvm 安装特定版本的 ruby。参见 https://owanateamachree.medium.com/how-to-install-ruby-using-ruby-version-manager-rvm-on-macos-mojave-ab53f6d8d4ec

确保您按照所有步骤操作。这对我有用。