我需要将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
brew link --overwrite --force ruby
我推荐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,请访问此链接。
打开终端:
sudo gem update --system
它的工作原理!
酿造专用溶液
更好的解决方案
从评论(马克西姆·卢齐克的功劳)来看,我还没有测试过,但似乎是一个更优雅的解决方案:
通过brew安装Ruby后,运行以下命令将链接更新到最新的Ruby安装
一个解决方案
使用brew就足够了。没有必要安装rvm,对我来说,它只是复杂的事情。
通过brew install ruby,您实际上是在安装最新的ruby(目前是v2.4.0)。但是,您的路径首先找到2.0.0。要避免这种情况,只需更改优先级(源)。我通过改变~/来做到这一点。配置及设置:
导出路径= / usr /地方/ bin:美元的道路
在此之后,我发现捆绑器gem仍然使用2.0.0版本。只需重新安装:gem install bundler
推荐文章
- 是否可以在MiniTest中运行单个测试?
- 如何在Ruby中生成a和b之间的随机数?
- 无法安装gem -未能建立gem本地扩展-无法加载这样的文件——mkmf (LoadError)
- 如何在Ruby中创建文件
- 什么是Ruby文件。开放模式和选项?
- Ruby数组到字符串的转换
- 如何分割(块)一个Ruby数组成X元素的部分?
- Maven检查存储库中更新的依赖项
- Ruby中“or”和||的区别?
- 如何测试参数是否存在在轨道
- 在Ruby中不创建新字符串而修饰字符串的规范方法是什么?
- RVM不是一个函数,用' RVM use…’不会起作用
- 了解Gemfile。锁文件
- 如何确定一个数组是否包含另一个数组的所有元素
- 是什么导致这个ActiveRecord::ReadOnlyRecord错误?