Ruby: Print Version String from Script

By Xah Lee. Date: . Last updated: .

Print version from the command line:

ruby -v

Print version from within a script:

# Ruby

p RUBY_VERSION
# "3.1.2"

Printing version from script is a important technique to find out which version your script is running. Because, you might have several version installed, and and it's harder to find out in terminal, because there are aliases, links, path environment variables, etc effect which Ruby version will start when you type ruby in shell.

Ruby Version Release Dates