How to execute a Ruby script in Terminal?
Solution 1:
Just call: ruby your_program.rb
or
- start your program with
#!/usr/bin/env ruby
, - make your file executable by running
chmod +x your_program.rb
- and do
./your_program.rb some_param
Solution 2:
Open your terminal and open folder where file is saved.
Ex /home/User1/program/test.rb
- Open terminal
cd /home/User1/program
ruby test.rb
format or test.rb
class Test
def initialize
puts "I love India"
end
end
# initialize object
Test.new
output
I love India
Solution 3:
Assuming ruby interpreter is in your PATH (it should be), you simply run
ruby your_file.rb
Solution 4:
To call ruby file use : ruby your_program.rb
To execute your ruby file as script:
start your program with
#!/usr/bin/env ruby
run that script using
./your_program.rb param
- If you are not able to execute this script check permissions for file.