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.
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")
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"
Finally, save the changes by running:
[System.Environment]::SetEnvironmentVariable("Path", $env:Path, "Machine")
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!