我需要将Ruby版本从2.0.0更新到最新版本。我不能使用一些宝石,因为我的版本没有更新。 前段时间我用Homebrew安装了Ruby。如何更新Ruby版本?
当前回答
如果出现“需求安装失败,状态: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
其他回答
打开终端并运行
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.x
如果它仍然显示ruby 2.0。,执行rvm use ruby-X.X命令。X——违约。
Windows 10操作系统的前提条件:
C编译器。你可以使用http://www.mingw.org/ 使命令可用,否则它将抱怨“bash: Make: command not found”。可以通过mingw-get install msys-make命令进行安装 在path环境变量中添加“C:\MinGW\msys\1.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 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
$ 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]
如果您没有显示更新的版本,那么
$ rbenv rehash
通过在存储库根目录中添加.ruby-version来设置存储库的本地版本:
$ cd ~/whatevs/projects/new_repo $ echo "2.3.1" > .ruby-version
对于OS X,请访问此链接。
一种快速将Ruby升级到v2.4+的方法
brew upgrade ruby
or
sudo gem update --system
您可以通过查看下载Ruby指定Ruby的最新版本。
获取最新版本: curl -sSL https://get.rvm.io | bash -s stable——ruby 安装: RVM安装2.2 使用它作为默认值: RVM使用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
推荐文章
- 如何记录Ruby代码?
- Ruby:包含的反义词是什么?Ruby数组?
- 在Ruby中,proc和lambda有什么区别?
- 如何传递参数到一个Rake任务与环境在Rails?
- 获取当前正在执行的方法的名称
- 如何在Rails中计算相对时间?
- 在Ruby中使用范围填充数组的正确方法
- “for”和“each”在Ruby中
- 我如何复制一个哈希在Ruby?
- Ruby/Rails:将Date转换为UNIX时间戳
- 我如何编码/解码HTML实体在Ruby?
- Ruby有一个string. startwith ("abc")内置方法吗?
- 如何从URL下载文件并保存在Rails中?
- 从字符串中移除子字符串
- 如何从Ruby数组中创建平均值?