欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2024-02-20 19:32:34
...

本文翻译自:How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite?

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. 我需要将红宝石版本从2.0.0更新到最新版本,因为我的版本未更新,所以我无法使用某些gems。 I had used Homebrew to install Ruby some time ago, How can i update my Ruby version? 我之前曾经用Homebrew安装Ruby,如何更新Ruby版本?


#1楼

参考:https://stackoom.com/question/2aG0m/如何在Mac-OSX-Yosemite中将Ruby版本-更新到最新版本


#2楼

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 terminal for the rvm command to work. 完成此操作后, 需要重新启动终端才能使rvm命令起作用。

Now, run rvm list known 现在,运行rvm list known

This shows the list of versions of the ruby. 这显示了红宝石的版本列表。

Now, run rvm install [email protected] to get the latest ruby version. 现在,运行rvm install [email protected]以获取最新的ruby版本。

If you type ruby -v in the terminal, you should see ruby XXX . 如果在终端中输入ruby -v ,应该会看到ruby XXX

If it still shows you ruby 2.0. 如果仍然显示ruby 2.0. , run rvm use ruby-XXX --default . ,运行rvm use ruby-XXX --default


#3楼

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/为什么使用rbenv? :

rbenv does… rbenv 确实...

  • Provide support for specifying application-specific Ruby versions . 提供对指定特定应用程序的Ruby版本的支持
  • Let you change the global Ruby version on a per-user basis. 让您按用户更改全局Ruby版本
  • Allow you to override the Ruby version with an environment variable. 允许您使用环境变量覆盖Ruby版本

In contrast with RVM, rbenv does not… 与RVM相比,rbenv 不…

  • Need to be loaded into your shell. 需要加载到您的外壳中。 Instead, rbenv's shim approach works by adding a directory to your $PATH . 而是rbenv的shim方法通过将目录添加到$PATH
  • Override shell commands like cd or require prompt hacks. 覆盖诸如cd类的shell命令,或要求立即进行**。 That's dangerous and error-prone. 这很危险,而且容易出错。
  • Have a configuration file. 有一个配置文件。 There's nothing to configure except which version of Ruby you want to use. 除了要使用哪个版本的Ruby,没有其他配置。
  • Install Ruby. 安装Ruby。 You can build and install Ruby yourself, or use ruby-build to automate the process. 您可以自己构建和安装Ruby,也可以使用ruby-build自动化该过程。
  • Manage gemsets. 管理宝石集。 Bundler is a better way to manage application dependencies. Bundler是管理应用程序依赖项的更好方法。 If you have projects that are not yet using Bundler you can install the rbenv-gemset plugin. 如果您有尚未使用Bundler的项目,则可以安装rbenv-gemset插件。
  • Require changes to Ruby libraries for compatibility. 需要更改Ruby库以获得兼容性。 The simplicity of rbenv means as long as it's in your $PATH , nothing else needs to know about it. 只要它在你的rbenv手段简单$PATH没有什么 别的需要了解它。

INSTALLATION 安装

Install Homebrew http://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

\n

UPDATE 更新
There's one additional step after brew install rbenv Run rbenv init and add one line to .bash_profile as it states. brew install rbenv之后,又需要执行另一步骤。运行rbenv init并在.bash_profile添加一行内容。 After that reopen your terminal window […] SGI Sep 30 at 12:01 — https://*.com/users/119770 之后,重新打开您的终端窗口[…] SGI 9月30日12:01 — https://*.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-version to your repo's root dir: 通过在.ruby-version库的根目录中添加.ruby-version来设置存储库的本地版本:

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

For MacOS visit this link 对于MacOS,请访​​问此链接


#4楼

Open Terminal: 打开终端:

sudo gem update --system 

It works! 有用!


#5楼

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

Or run the latest command from ruby: 或者从ruby运行最新的命令:

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

#6楼

Simplest way is definitely to enter the following command in the terminal: 最简单的方法肯定是在终端中输入以下命令:

sudo gem update --system

You can add the flag --no-document if you do not want to download the documentation. 如果不想下载文档,可以添加--no-document标志。 Here is sample output after running the command: 这是运行命令后的示例输出:

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
相关标签: ruby version