Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a Ruby script in Terminal?

Tags:

terminal

ruby

I've set everything up that I need on my Mac (Ruby, Rails, Homebrew, Git, etc), and I've even written a small program. Now, how do I execute it in Terminal? I wrote the program in Redcar and saved it as a .rb, but I don't know how to execute it through Terminal. I want to run the program and see if it actually works. How do I do this?

like image 989
Tom Maxwell Avatar asked Jan 04 '12 02:01

Tom Maxwell


People also ask

How do I open Ruby console in terminal?

Open up IRB (which stands for Interactive Ruby). If you're using macOS open up Terminal and type irb , then hit enter. If you're using Linux, open up a shell and type irb and hit enter. If you're using Windows, open Interactive Ruby from the Ruby section of your Start Menu.

How do I make a Ruby script executable?

You can make the script executable with the following command: chmod +x hello. rb . chmod is a shell command that allows us to change the permissions for a file. The +x specifies that the script should be executable.


1 Answers

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
like image 111
Robin Avatar answered Sep 24 '22 08:09

Robin