Can't get past "Hello world"

I’m trying to learn the language by following along with a Youtube video so I type puts "hello world" into the text editor but when I try to execute the code in terminal it says the file doesn’t exist. What’s happening?

How are you trying to execute the code? And what’s the error exactly?

Based on what you said, are you sure the file you’re trying to execute exists?

What video are you watching?

Can you open your command prompt and type “crystal -v” (without the quotes, of course)
and then let us know what it prints out when you run that command?

so I type puts "hello world" into an Atom file named crystal_tut.cr, when I call the file in terminal with crystal crystal_tut.cr I get Error: file 'crystal_tut.cr' does not exist

And you’re sure you’re in the same directory as you created the file? E.g. does cat crystal_tut.cr also fail?

Same directory as the file you say, how do I do that? and cat crystal_tut.cr also fails with the message cat: csytal_tut.cr: No such file or directory. Do I need prior knowledge of Ruby to be able to understand Crystal?

1 Like

Ah, okay, so when you save the file in your editor, you’ll need to make sure that you can navigate to that same directory, or folder, where that file is.

You don’t need Ruby to write Crystal, it’s just very familiar to those who have. Both are relatively simple. Everything can seem overwhelming and alien when you are first getting started, just try and push through it and be okay with not knowing certain things.

So, if you are on macOS/Linux, you can type ls at the command prompt to list out the contents of that directory, and you can use cd to navigate inside a directory. So, if I wanted to go from Home/ → Home/code/ I’d type cd code from the Home directory. You can also type cd .. to go “up” one level. So, from Home/code/ if I typed cd .. I’d be back in Home/

These are pretty basic concepts for navigating. Try and navigate into the directory where your crystal_tut.cr file is from wherever your command prompt is opened. Your editor should say somewhere the filepath where the file is being saved. (sorry, never used Atom)

Are you sure you didn’t make a typo?: “csytal_tut.cr”

2 Likes

Even when i correct the typo the issue persists.

To be clear this isn’t a Crystal issue. The gist of it is the Crystal file you created in you text editor isn’t in the same directory as your terminal, which is why both crystal and cat commands fails saying the file doesn’t exist.

As @wrq mentioned, you can prove this by typing ls in your console and see that the file you’re trying to execute isn’t there. You could also go a step further and do echo 'puts "Hello world"' > test.cr && crystal test.cr which should print Hello world.

If you are new to linux/programming/computers you’d probably be better off starting out with a tutorial on how to navigate the file system on your machine before jumping into a Crystal tutorial, or any programming lang tutorial for that matter.

1 Like

Okay, I’m using the Linux distro OpenSUSE Tumbleweed and only now am I realizing that applications don’t even have a folder in the file explorer.

I use OpenSUSE Tumbleweed most days for work. Feel free to DM me, and I’m happy to do my best to answer any questions you have or problems that come up.