Jules Jules - 5 years ago 216
Ruby Question

Run a Ruby program in mac terminal

i'm new to programming and a couple of days ago i started a ruby course on codecademy. i found that instead of an ide, for ruby is usually used Sublime Text. the problem is that i can't run a simple program from the terminal of the mac by typing " ruby test.rb " (test is the name of the script). in another question in here said that it was enough, but not in my case. what can i do to run it ? here's the code anyway:)

def main
print "Enter yout name: "
input = gets.chomp
end
main


it's really simple but i wanted to write down something to test it first
plus i followed the first paragraph (installing) and the "Running ruby code" part of this ruby guide:
https://launchschool.com/books/ruby/read/preparations
what should i do? thanks in advance!

Answer Source

Are you in the folder where the test file is? The steps to run a ruby program from terminal are:

  1. Navigate to folder where your ruby file is by typing cd foldername until you've drilled down to where the file is. If you are unsure what is in the current folder, type ls to list all files & folders.
  2. When you've gone into the proper folder, type ls again and you should see test.rb. The extension of the file should be .rb not .tb. Don't know if that's a type or not.
  3. Type ruby test.rb and your program should work. I mimicked your code and it runs on my Mac terminal.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download