我需要将Ruby版本从2.0.0更新到最新版本。我不能使用一些宝石,因为我的版本没有更新。 前段时间我用Homebrew安装了Ruby。如何更新Ruby版本?
当前回答
sudo gem update --system
然后重启电脑
其他回答
由于React Native 0.70和macOS Monterrey,最终使用了下面的步骤。
$ brew install ruby
Edit
open -e ~/.zshrc
设置环境变量$PATH。将此添加到~/的末尾。zshrc中。Mac英特尔:
if [ -d "/usr/local/opt/ruby/bin" ]; then
export PATH=/usr/local/opt/ruby/bin:$PATH
export PATH=`gem environment gemdir`/bin:$PATH
eval "$(rbenv init -)"
fi
苹果硅
if [ -d "/opt/homebrew/opt/ruby/bin" ]; then
export PATH=/opt/homebrew/opt/ruby/bin:$PATH
export PATH=`gem environment gemdir`/bin:$PATH
eval "$(rbenv init -)"
fi
不想brew更新你的版本?
$ brew pin 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.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,请访问此链接。
如果你在Mac上,使用rvm来安装特定版本的Ruby。参见如何在MacOS Mojave上使用Ruby版本管理器(RVM)安装Ruby
确保你遵循了所有的步骤。这对我很管用。
在终端:rvm gemset使用全局
推荐文章
- Rails:dependent =>:destroy VS:dependent =>:delete_all
- 我可以在不包含Ruby模块的情况下调用实例方法吗?
- Node -使用NODE_MODULE_VERSION 51根据不同的Node.js版本编译
- 如何将新项目添加到哈希
- 测试一个Ruby类是否是另一个类的子类
- 什么时候使用Struct vs. OpenStruct?
- 数组到哈希Ruby
- 我如何让红宝石打印一个完整的回溯而不是截断一个?
- 如何使用RSpec的should_raise与任何类型的异常?
- 如何创建退出消息
- 忽略GEM,因为没有构建它的扩展
- 在Gem::Specification.reset期间未解决的规格:
- Delete_all vs destroy_all
- 双引号vs单引号
- 用any可以吗?'来检查数组是否为空?