在Windows上安装Go无法正常工作吗?

huangapple go评论103阅读模式
英文:

Go install not working on Window?

问题

我今天刚在我的Windows电脑上安装了Golang,并且设置了%GOPATH%。然而,当我运行go install {...}来安装各种二进制文件时,Windows找不到可执行文件。我的%GOROOT%C:\Go,这是默认的.msi安装位置。

  1. PS C:\Users\{user}\Development\go> ls
  2. 目录: C:\Users\{user}\Development\go
  3. Mode LastWriteTime Length Name
  4. ---- ------------- ------ ----
  5. d---- 12/11/2015 9:02 PM bin
  6. d---- 12/11/2015 11:08 AM pkg
  7. d---- 12/11/2015 11:08 AM src
  8. C:\Users\{user}\Development\go>echo %GOPATH%
  9. C:\Users\{user}\Development\go

我是否错误地设置了环境变量?

英文:

I just installed Golang on my Windows box today, and I have my %GOPATH% set. However, when I run go install {...} for various binaries, Windows can't find the executables. My %GOROOT% is C:\Go, the default .msi install location.

  1. PS C:\Users\{user}\Development\go> ls
  2. Directory: C:\Users\{user}\Development\go
  3. Mode LastWriteTime Length Name
  4. ---- ------------- ------ ----
  5. d---- 12/11/2015 9:02 PM bin
  6. d---- 12/11/2015 11:08 AM pkg
  7. d---- 12/11/2015 11:08 AM src
  8. C:\Users\{user}\Development\go>echo %GOPATH%
  9. C:\Users\{user}\Development\go

Do I have the environmental variables set incorrectly?

答案1

得分: 4

> Windows无法找到可执行文件

如果你指的是通过go install从你的go程序构建的可执行文件,并且由Go在%GOPATH%\bin中提供,你只需要将%GOPATH%\bin添加到你的PATH环境变量中(除了%GOROOT%\bin)。

  1. set PATH=%PATH%;%GOPATH%\bin
  2. cd %GOPATH%\src\path\to\a\go\project
  3. go install

然后你就可以调用你的可执行文件了,Windows会在%GOPATH%\bin(即C:\Users\{user}\Development\go\bin文件夹)中找到它。

英文:

> Windows can't find the executables

If you mean the executable built from your go programs (by go install) and delivered by Go in %GOPATH%\bin, all you need is to add to your PATH environment variable %GOPATH%\bin (in addition of %GOROOT%\bin)

  1. set PATH=%PATH%;%GOPATH%\bin
  2. cd %GOPATH%\src\path\to\a\go\project
  3. go install

Then you can call your executable, and Windows will find it in %GOPATH%\bin (the C:\Users\{user}\Development\go\bin folder)

huangapple
  • 本文由 发表于 2015年12月12日 12:10:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/34236162.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定