{

How to get a ruby version in a project Ruby on Rails with examples


This short tutorial explains how to find the ruby version installed on a project.

How to find the ruby version in a project?

In Terminal, you can type the ruby --version command if ruby is installed.

C:\Users\Kiran>ruby --version
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x64-mingw32]

To know the ruby version in the interactive ruby terminal(IRB) console.

C:\Users\abc>irb
irb(main):001:0> RUBY_VERSION
=> "2.7.0"
irb(main):002:0>

In Ruby, You can use other global constants like the below in the Ruby on Rails application.

RUBY_PATCHLEVEL RUBY_PLATFORM RUBY_RELEASE_DATE RUBY_DESCRIPTION

Here are an example commands for the Ruby version platform, release date, and complete release version

irb(main):001:0> RUBY_VERSION
=> "2.7.0"
irb(main):002:0> RUBY_PATCHLEVEL
=> 0
irb(main):003:0> RUBY_PLATFORM
=> "x64-mingw32"
irb(main):004:0> RUBY_RELEASE_DATE
=> "2019-12-25"
irb(main):005:0> RUBY_DESCRIPTION
=> "ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x64-mingw32]"
irb(main):006:0>

You can also print the ruby version programmatically using puts to console.

puts RUBY_DESCRIPTION

Output:

ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]

Ruby version in Heroku environment

You can run the ruby -v command with Heroku run

heroku run "ruby -v"

In the Linux environment, You can type which command to know the ruby version and location.

which -a ruby
THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.





Related posts

How to install and uninstall gem in Ruby Programming| Ruby on Rails by Example

How to do sum of array numbers in Ruby with examples

How to check the type of a variable is Ruby| Ruby on Rails By Example

How to convert Class or Hash Object to JSON Object Ruby| Ruby on Rails By Example

How to remove duplicate elements from an array in Ruby with examples

How to Convert current Unix timestamp epoch to DateTime in Ruby Programming| Ruby on Rails by Example

How to remove an element from an array in Ruby Programming| Ruby on Rails by Example