Powershell and "$ rustc" command :(


Hey guys!

I’m pretty new to launching a compiler through a commandprompt. I use PowerShell for that now. And actually managed to install Rust and check its version via “rustc --version”.

But now I made a directory for the project and created a file called “main.rs” and added the main method in it like the tutorial told me.

*PS C:\Users\Falke\Desktop\rustproject\hello_world> rustc main.rs** * : Die Benennung "" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines ausführbaren* *> Programms erkannt. Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern enthalten), und* *> wiederholen Sie den Vorgang.* *> In Zeile:1 Zeichen:1* *> + rustc main.rs
> + ~
> + CategoryInfo : ObjectNotFound: ($:String) [], CommandNotFoundException
> + FullyQualifiedErrorId : CommandNotFoundException

Thats what PowerShell pops on my head. I think it is a simple thing but sorry guys don’t know the keywords to search for in google so I just can’t get up with a solution. I’m sure I have to anyhow add “rustc” to a commen command for PowerShell so I can use it just like that. But I can’t find a way or google answer that brings me to that.

Would be awesome if you guys can help me out!

greets Charlie!

Who doesn't the installer add rust to PATH anymore?

Is the $ a part of the prompt or did you write it yourself? I get the feeling that that’s what PowerShell complains about, but I may misunderstand it because of the language.


Hey there!

Thanks for your reply but in fact this message here appears without the $ so that might not be the issue:

PS C:\Users\Falke\Desktop\rustproject\hello_world> rustc main.rs
rustc : Die Benennung “rustc” wurde nicht als Name eines Cmdlet, einer
> Funktion, einer Skriptdatei oder eines ausführbaren Programms erkannt.
> Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist
> (sofern enthalten), und wiederholen Sie den Vorgang.
> In Zeile:1 Zeichen:1
> + rustc main.rs
*> + ~~~~~*
> + CategoryInfo : ObjectNotFound: (rustc:String) [], CommandNotFou
> ndException
+ FullyQualifiedErrorId : CommandNotFoundException


So it says “rustc” could not be identified as a Cmdlet, a function, a scriptfile or a executeable program.


Check if rust installation (that is, the rust-directory) is in your PATH system variable.
The last two errors are very clear: ObjectNotFound, CommandNotFound

It is “natural” to PowerShell to complain about non-existing CmdLets because it uses those by default. Of course, you want to execute a binary (rustc). In this case, just ignore PowerShell’s lingo (CmdLets etc.). :smile:

The PATH variable can be set via System Properties/Environment Variables, or in German Systemsteuerung/Umgebungsvariablen

How to find System-Settings (in German)


Shouldn’t the installer set PATH properly? Maybe a reboot is needed.


In rare cases the PATH variable is already “too long” and can’t be modified anymore. Therefore it is far better to modify the PATH manually.


AWESOME thanks for that advice!

It might be a casual thing to know but since I so rarely use these cases it wasn’t that obvious for me!

Now I can start Rusting :smiley:


You’re welcome! :smiley:

Have fun and share your experience.


hi, I installed rust in windows by following “the book”. i also checked the path as mentioned above it is correct. but when i try to compile the hello world program it shows

PS C:\Users\Katsukage> fn main.exe() {
println!(“Hello, world!”);
At line:1 char:13

  • fn main.exe() {
  •         ~

An expression was expected after ‘(’.
+ CategoryInfo : ParserError: (:slight_smile: [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedExpression
I have basic knowledge of c and c++ only. what am i doing wrong.
im using windows 10, in powershell ISE


That ‘main.exe’ should be just ‘main’


It looks like you’re trying to type function directly into PowerShell console. It’s not how it works. Instead, you want to create a Rust project, put hello world in main.rs, and run it with cargo run.


yes exactly. how would i go about doing the steps that you mentioned? if possible link any rookie tutorial because im sure im gonna have problems in fututre as well. thanks for all your help.


How would i create the main.rs file?


Just using any code editor :slight_smile:


sorry to be such a bother but what code editor?
Let me recap what i have done.
I installed vc++, rust and visual rust.
I got vc++ installer folders and C:\Users\Katsukage directory got .rustup and .cargo folder. whenever I double click any application file cmd flashes for a brief moment and nothing happens. taskmanager also doesnt show any rust related activities. im using windows 10 os.
it`s been 4 days since ,i am searching for the solution please help. thanks in advance


Any editor would be ok, even notepad or notepad++. From the ones you listed, probably visual rust (this is the visual studio plugin, right?) would be the most appropriate. What matters is that that you save the file as (you can choose different directory, of course):


This is expected. These programs don’t have any GUI, they are meant to be run from the console, like that (make sure you use cd first to navigate to the directory where the main.rs is):

rustc main.rs

You should follow the instructions here, (and ignore the dollar signs, they only mean “type this command in the shell”).


ok, so i did compile (in powershell) the program. it created a .exe and a .pdb file in the same folder. I cant seem to open any of these file from the explorer as well as powershell. in powershell if i write
rustc hello.exe
error: couldn’t read “hello.exe”: stream did not contain valid UTF-8
and writing hello.rs created those 2 files in the first instance.

also how would i use the visual rust editor?
again thank you very much for bearing with me :raised_hands:


The instructions from the book say:

rustc main.rs ./main
Hello, world!

>In Windows, replace `main` with `main.exe`.

So I guess (don't have Windows to test), that you should just type `./hello.exe` or `.\hello.exe` in powershell/cmd to run the compiled binary.


Visual Rust is a Rust extension for Visual Studio. Visual Studio is not just an editor, but an IDE (everything from managing projects, source control, build system to debugger).
That means, you work entirely inside Visual Studio and don’t use PowerShell or rustc/cargo directly.

You probably have to create an new Rust-Project inside Visual Studio and begin from there. It certainly easier if you are already familiar with Visual Studio from another language, e.g. C++.

Just be aware, that this is an entirely different environment and most things you find on the internet don’t apply because they assume that you work from the command line.