Sign in to follow this  

How do i run my Ruby programs?

This topic is 2100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know i have to use cmd to run my Ruby files but when i try nothing happens. The tutorials say to go into cmd and type "ruby my_program.rb" where "my_program.rb" is my file and ruby is supposed to do something. But when i do this nothing happens and i have my file named correctly. Do i need to have it in a certain place on my computer?

Share this post


Link to post
Share on other sites
Not that i know of. I downloaded the ruby installer for 1.9.2 and thats all.

Share this post


Link to post
Share on other sites
When you are trying to run the program from the cmd prompt do you first navigate to the proper directory containing the ruby file? Also make sure it installed properly by typing "ruby -v" on the command prompt.

Share this post


Link to post
Share on other sites
It just keeps saying ruby is not recognized as an internal or external command.

EDIT: Although, when i use the start command prompt with ruby option it give me rubys info when i type ruby -v. Maybe i need to learn how to navigate to the correct directory so lets try that?

Share this post


Link to post
Share on other sites
Haven't used the windows command line much (I use unix/linux) but after looking online a bit typing "cd" with no arguments will give you the directory you are currently working in the you will us cd to change directories.

"cd ../" is up one level from the current location, "cd name" changes to the directory named "name" within the current directory or you could do absolute path such as "cd c:\Users\K1NNY\Documents\Ruby" or wherever your stuff is stored. But you need to run the command in whatever form got ruby to be recognized as a command.

Once you are in the right folder try running the program again

Share this post


Link to post
Share on other sites
No problem. If you are interested here is a very basic introduction to some commonly used command line commands in Windows http://www.bleepingcomputer.com/tutorials/windows-command-prompt-introduction/

Share this post


Link to post
Share on other sites
If you want to be able to run Ruby from an arbitrary directory (which generally you do), you must set your "PATH" [i]environmental variable[/i] to include Ruby's location. The PATH variable is consulted when a command is run - it is searched in some order that I cannot remember. Some Ruby installers will give you the option to do this. Other ruby installers will give you a start menu entry which will create a command prompt with the correct path - this sounds like what you have.

To make it apply to any command prompt, right click on "My Computer", choose "Properties", select the "Advanced" tab, press the "Environmental Variables" button (I believe the layout is mostly the same on different Windows versions). In the "user variables" area, either create a new one called PATH and put the full ruby directory in it (e.g. something like C:\some\directory\ruby-<version>\bin). If one exists, carefully append the directory to it, adding a semicolon to separate it from any previous values (e.g. if PATH is currently [b]C:\foo\awesome\bin;C:\bar\mediocre\bin [/b]then edit it to [b]C:\foo\awesome\bin;C:\bar\mediocre\bin[u];C:\some\directory\ruby-<version>\bin[/u][/b]).

Now, you should be able to fire up a new command prompt (e.g. start -> run "cmd") and get ruby to work in any directory (as mentioned, use ruby -v to ensure it is working). Note that changing these variables will not be propagated to existing command prompts, so if you made a mistake and need to try again you'll have to start a new command prompt to see the changes. You can use the command "echo %PATH%" to see what it is currently set to in your command prompt.

Share this post


Link to post
Share on other sites

This topic is 2100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this