Home  >  Article  >  Backend Development  >  Why is the \'go\' command not recognized in my terminal?

Why is the \'go\' command not recognized in my terminal?

Susan Sarandon
Susan SarandonOriginal
2024-11-03 06:49:30308browse

Why is the 'go' command not recognized in my terminal?

Error: 'go' Command Not Recognized

After executing the command "go run main.go," you 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.

Solution

To fix this error, you need to add the path to the Go executable to your system's environment variables. Here's how:

  1. Open your command prompt or terminal window.
  2. Run the following code:
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine")

This will retrieve the current path variable.

  1. Append the path to the Go executable to the path variable. For example, if Go is installed in the "C:Go" directory, add the following to your path:
;C:\Go\bin

The semicolon (;) separates the new path from the existing path.

  1. Save the changes by typing:
$env:Path = $env:Path + ";C:\Go\bin"

You may need to replace "C:Gobin" with the correct path to your Go installation.

  1. Close and reopen your command prompt or terminal window for the changes to take effect.

Now, you should be able to run the "go run main.go" command without encountering the error.

The above is the detailed content of Why is the \'go\' command not recognized in my terminal?. 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