Home > Mobile >  Which ruby version am I using?
Which ruby version am I using?

Time:09-16

I'm not sure what Ruby version is being used on my device (macOS) by default.

ruby -v outputs ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]

brew list ruby --versions outputs ruby 3.0.2

rbenv versions outputs

  system
* 2.7.4 (set by /Users/nlakritz/.rbenv/version)

CodePudding user response:

If ruby -v shows 2.6.3, then you are using the ruby which ships with the system by default. You can confirm this in several ways. Running the shell command which ruby will show /usr/bin/ruby. Checking your PATH will show /usr/bin earlier than the location of the homebrew or rbenv installations.

If you wish to run one of the others, you can put it earlier on the PATH or invoke it explicitly by giving the fully qualified name such as /usr/local/opt/ruby/bin/ruby myscript.rb. Another alternative which avoids twiddling the PATH variable is to use a shebang line at the beginning of different scripts pointing explicitly to the version to use with that script.

CodePudding user response:

It depends what you mean by 'default'. If you're running a file with ruby filename then the version you are using is 2.6 (because you're running the same Ruby as ruby --version).

If you're running a file directly (eg. ./filename.rb) then it depends on the shebang line in the file. For example, the file could start with the line #!/usr/bin/ruby, so to check which version of ruby that file is running on, you could call /usr/bin/ruby --version.

Hopefully that helps, but I'm not 100% sure I understood what you're asking - so let me know :)

CodePudding user response:

Try this:

$ which ruby
/usr/bin/ruby
$ irb
irb(main):001:0> RUBY_VERSION
=> "2.7.0"

So, rbenv is ignored, I think you're missing this in your path:

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
ruby -v # should say 2.7 now

And if it says 2.7, you can add the export and eval commands at the bottom of your ~/.bashrc to load it every time you open a shell, thus kicking off rbenv override.

I would bet 2.6 for you, ie ruby -v.

  •  Tags:  
  • ruby
  • Related