I am receiving the error No such file or directory in my command line and I think it's because I am not saving the ruby files somewhere specific. All I did was create a random folder where I would save my ruby files.
Do I need to save my scripts in the original ruby folder? Thanks!
** This is Windows 7.
More info - All I did was make a simple file named "Matz.rb" because I'm currently reading the O'reilly Ruby book. In my code all I wrote was puts "Hello Matz". I saved this on my desktop. When I go to the command line it and I write ruby matz.rb it says "ruby: No such file or directory -- matz.rb " Please help :(
If this has something to do with PATH or shells, I honestly have no idea what those really are because I just started coding last night.
You are most likely not in the right folder. You somehow need to tell the ruby interpreter where it is looking for the file.
Either make sure you're in the right folder - the
cd
command allows you to change location:or specify the path explicitly:
By default, the ruby interpreter will look in your current directory (the location shown in your prompt) for whatever filename you give it.
Edit: I'll attempt to explain what I mean step-by-step.
When you initially open the command prompt, it will indicate what folder you are in (your "current working directory") in the prompt:
In the above example, you are working in the
C:\Users\YourUsername
folder.cd
command. For example, typingcd Desktop
moves you into the folder calledDesktop
, assuming such a folder exists in your current locationcd C:\Another\Place
ruby Matz.rb
, the system knows how to find theruby
program because the installer placed its location into thePATH
environment variable. Don't worry about this too much, this just explains the "magic" by which it knows whatruby
means, no matter where you are.Matz.rb
) by looking in the current directory. To re-iterate, it is looking in whatever folder is written right there in your prompt.To go from a new command window that you've just opened, to typing
ruby Matz.rb
and having it work, you need to do the following:If we assume your username is
alex
and you have a folder on your desktop called "rubycode", which containsMatz.rb
, you could do this:C:\Users\Alex
cd Desktop\rubycode
. All subsequent commands will be working from within this folder.ruby
command, specifying the file:ruby Matz.rb
I hope that makes sense.