Terminal not executing Ruby files
Solution 1
If you have named your file "Calc.rb" you'll need to run ruby Calc.rb
(capital "C").
Also make sure that you're navigating the /Desktop
directory — e.g. type
cd ~/Desktop
ruby Calc.rb
You can use ls
to get a list of all the files in the current directory. You could use that to see if the file you're trying to execute actually exists.
Solution 2
In Terminal, did you change your current directory to your desktop before running your program ?
If your program is stored on your desktop, you first need to change directory to your desktop or your Ruby script will not be found.
$ cd Desktop
$ ruby calc.rb
Solution 3
ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
C:\Ruby Programs>ruby calc.rb
ruby: No such file or directory -- calc.rb (LoadError)
C:\Ruby Programs>ruby calc.rb.txt
3
One should not have to add the .txt extension while attempting to run the program from whithin the program's home folder. I have to though.
Admin
Updated on June 12, 2022Comments
-
Admin almost 2 years
I'm pretty much entirely new to programming, so bear with me. I am on a Macbook Pro running 10.6.6.
At the beginning of the "Learn to Program" tutorial are these directions:
Save your program (yes, that's a program!) as calc.rb (the .rb is what we usually put at the end of programs written in Ruby). Now run your program by typing ruby calc.rb into your command line. It should have put a 3 on your screen. See, programming isn't so hard, now is it?
When I type
ruby calc.rb
I get the following error:ruby: No such file or directory -- calc.rb (LoadError)
What am I doing wrong? "Calc.rb" is saved on my desktop, if it matters.
-
Admin over 13 yearsYup, I was actually on my school's wireless directory (?). But I changed it to desktop and the file executed.
-
Hossein over 12 yearsIf you're saving with Notepad, make sure you choose
All Files (*.*)
inSave As Type
in its Save dialog. -
Nikana Reklawyks over 11 yearsThat's not his problem, right? He has the well-named file on his desktop, he said. Also, text is more understandeable than prompts, for human who are not machines.