Home >Backend Development >Golang >Why is the `go` command not recognized when I run `go run main.go`?

Why is the `go` command not recognized when I run `go run main.go`?

Linda Hamilton
Linda HamiltonOriginal
2024-11-03 12:42:30947browse

Why is the `go` command not recognized when I run `go run main.go`?

Error: "The term 'go' is not recognized" While Running 'go run main.go'

When executing the command go run main.go, users might 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.

This issue arises because the 'go' command may not be accessible from the current path. To resolve this, run the following command in the terminal:

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

This modifies the system's path variable to include the appropriate path to the 'go' command. After running this command, users can execute 'go run main.go' without encountering the error.

The above is the detailed content of Why is the `go` command not recognized when I run `go run main.go`?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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