How do you run a .rb file in mac?

D

Dark Lord

Hello. I created a ruby program in Smultron, but I couldn't figure out
how to run it on a mac. Should I download anything to execute it? I
thought Macs had ruby pre -installed. Thanks.
 
D

Dark Lord

Nathan said:
Open /Applications/Utilities/Terminal.app and type: ruby file.rb

You could also type irb to get an interactive console.

Nate

Thanks a lot, Nate. It worked. :)
 
D

Damian Terentyev

Good day!

Open /Applications/Utilities/Terminal.app and type: ruby file.rb

You could also type irb to get an interactive console.

Nate

You can also add the following line at the very beginning of your ruby
script:

#!/usr/bin/env ruby

and then run the following command in the Terminal.app:

chmod u+x /path/to/your/file.rb

Then you'll be able to invoke the file by its name.

By the way, ruby that comes with OS X is a bit outdated, so it will be
not a bad option to install a fresh version. The simplest approach is
to use MacPorts.

Your sincerely,
Damian/Three-eyed Fish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top