Help with Hello World fail

I am running Linux Mint 19.2 Tina - as per tutorial in specified folders creating with this code

fn main() {
    println!("Hello, world!");

running "rustc" - seems to pause a second and then just bring up a new prompt, as if nothing happened. No Hello World. In the directory /home/projects/hello_word/ there are two files main and

My rustc --version is: rustc 1.40.0 (73528e339 2019-12-16)

Where did I go wrong? Is there something else I can insert into the code that might help with troubleshooting?

Rust is compiled language. It means that the program running consists of two phases: compilation, i.e. translation from the Rust code into the native machine code, and execution of the resulting code.

When you run rustc, you're instructing compiler to do compilation phase. It would read the file passed in (and all modules defined in it, if there were any), check syntax, check types, etc., and then generate the executable file, which by default has the same name as the source file, but without extension (on Linux) on with extension .exe (on Windows). To run the program, you simply run this executable file - in you case it'll be `./main'.

You can check this in the Book, which I hightly recommend anyway.


thank for your graciousness replying to this, excluding the ./main was a glaring omission on my part. Your explanation is great, thank you.

1 Like

I am a noob too, but I am very curious why you are calling rustc directly?

If you execute: cargo run in the root directory of the project the program will be compiled and then run.

The Rust book's first Hello World exercise introduces rustc briefly before moving on to Cargo.


Ha! It hasn't been that long since I actually read the chapter :thinking:

Somewhere between toddler, holidays, and the rest of the book I completely forgot about that chapter...

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.