tags:

views:

442

answers:

3

I'm following this guide:

http://www.math.umd.edu/~dcarrera/ruby/0.3/chp_01/programs.html

and I'm trying to create my first ruby program. So I wrote it in a text editor, but now I dont know how to open through terminal. Rather, where should I be saving the program to (directory).

Thanks!

(I'm new to programming on mac) :(

A: 

As long as Ruby is on the path, you should be able to execute your .rb file from any directory. However, I'm not a Mac user, so I'm not sure how to check or set your path.

Thomas Owens
In terminal, simply enter echo $PATH
Reed Olsen
that produced: usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/binHow can I put the file in any of those folders?
Elliot
I'm going community wiki, since it looks like he needs more help than I can provide, simply because I don't use a mac. If anyone wants to edit this post to explain how to add ruby to the path, feel free.
Thomas Owens
Ruby is in the path by default on Mac OS 10.5 (Leopard). I'm not sure that's the problem at hand.
Reed Olsen
Ah. I see what was going on. Yeah, I forgot how in OS 10.5 it's all set up for you - I actually had some problems getting Ruby set up on my machine because the resident Ruby guru used a Mac and had everything all set up out of the box.
Thomas Owens
+2  A: 

Just to clarify, are you trying to execute your program from any directory? Or do you just want to run it in its own directory? By putting it in the /usr/bin directory, you will be able to execute it without typing the entire path to your program.

For example, if I have a ruby program in /Users/reedolsen/program.rb, I can run it by typing

ruby /Users/reedolsen/program.rb

By putting program.rb into /usr/bin, you can simply type ruby program.rb from anywhere and it will execute.

To copy your file to /usr/bin, use the following command

cp /path/to/yourfile /usr/bin/yourfile
Reed Olsen
Thank you, this solved my problem!
Elliot
A: 

I've added something like

export PATH=$PATH://bin

to the .profile (or maybe the .bashrc - I'm not at my mac now and cannot check which one) file in my home directory and put all those scripts into the bin folder in my home directory.

No need to put the files into /usr/bin or anything like that.

After you've added the above line to .profile, either restart Terminal or run

. .profile

to get it working.

Thomas Müller