How to run Ruby code from terminal? How to run Ruby code from terminal? ruby ruby

How to run Ruby code from terminal?


If Ruby is installed, then

ruby yourfile.rb

where yourfile.rb is the file containing the ruby code.

Or

irb

to start the interactive Ruby environment, where you can type lines of code and see the results immediately.


You can run ruby commands in one line with the -e flag:

ruby -e "puts 'hi'"

Check the man page for more information.