Home > Backend Development > Golang > Why Can\'t I Run \'go run main.go\'?

Why Can\'t I Run \'go run main.go\'?

Barbara Streisand
Release: 2024-11-02 22:02:02
Original
460 people have browsed it

Why Can't I Run

Troubleshooting "go: The term 'go' is not recognized" Error in Windows

When attempting to execute "go run main.go," you may encounter the following error:

go : The term 'go' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Copy after login

To resolve this issue, you need to add the Go installation directory to your environment variables. Here's how to do it:

$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
Copy after login

This command retrieves the current value of the "Path" environment variable. Next, append the path to the Go installation directory to the value. For example, if Go is installed in "C:Go", use the following command:

$env:Path += ";C:\Go\bin"
Copy after login

Finally, save the changes by running:

[System.Environment]::SetEnvironmentVariable("Path", $env:Path, "Machine")
Copy after login

After completing these steps, restart your terminal and try running "go run main.go" again. The error should be resolved.

The above is the detailed content of Why Can't I Run 'go run main.go'?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template