GOPATH值设置

时间:2014-08-26 06:48:35

标签: windows go

我用go1.3.1.windows-amd64.msi安装go,在安装GOROOT是默认设置后,我找到了 在PATH中D:\ Programs \ Go \ bin,然后我创建一个GOPATH环境变体, 当使用' go get'命令,发生错误:

包github.com/coreos/etcd:无法下载,$ GOPATH一定不能设置为$ GOROOT。有关详细信息,请参阅:go help gopath

操作系统:Windows 7

GOPATH会与GOROOT发生冲突吗?

如何设置这两个PATH值?

4 个答案:

答案 0 :(得分:25)

  • GOROOT必须引用您安装GO的文件夹
  • GOPATH必须引用一个空文件夹,该文件夹将是 workspace (src / pkg / bin用于您的项目)

在用户环境变量中添加这两个变量。

go get github.com/coreos/etcd应该:

  • 下载%GOPATH%/src/github.com/coreos/etcd中的来源(src为您创建)
  • %GOPATH%/pkg/windows_amd64中编译(pkg/是为您创建的,windows_amd64反映了您的Windows架构)
  • 使用go install,将其安装在%GOPATH%/bin中(bin/也是为您创建的)

注意:使用Go 1.8+(2017年第2季度),默认情况下({在Windows上)GOPATH可能会为您设置%USERPROFILE%/go。 在Linux上,它将是 $HOME/go :请参阅issue 17262


三年后更新2018年:GOPATH已经过时了 Go 1.11 modules

mkdir newProject
cd newProject
set GO111MODULE=on
go mod init myproject

答案 1 :(得分:4)

我遇到了同样的问题。但是,我按照教程中的说法设置了所有内容,但忘记重新启动cmd。所以步骤是:

  1. 下载并安装Go分发(自动设置GOROOT变量)
  2. 在工作区的任意位置创建新文件夹,创建3个目录:binsrcpkg
  3. 然后转到控制面板 -> 所有控制面板项 -> 系统 -> < strong> Advansed System Settings ->标签高级 -> 环境变量 ->点击系统可变性 ->变量名称= GOPATH,变量值= Your:\directory\that\you\created
  4. >新
  5. 完成后,重新启动您的cmdBash重要)并设置GOPATH 。要确保运行go env,您就会看到自己的价值。

答案 2 :(得分:0)

您不应设置$GOROOT

键入export GOROOT=""以解决您的问题。

答案 3 :(得分:0)

// when this Observable emits, the concurrency is recalculated const mySwitch = new Subject<number>(); let myConcurrency = 1; // this block emits five times, every time setting a new value for the concurrency // and the making mySwitch emit merge(interval(1000).pipe(map(i => i + 2)), of(1)) .pipe( delay(0), take(5), tap(i => { myConcurrency = i * 2; console.log("switch emitted", i); mySwitch.next(i); }) ) .subscribe(); // source is an hot Observable which emits an incresing number every 100 ms const source = new Subject<number>(); interval(100) .pipe(take(100)) .subscribe(i => source.next(i)); // this is the core of the logic // every time mySwitch emits the old subscription is cancelled and a new one is created mySwitch .pipe( switchMap(() => // defer is critical here since we want a new Observable to be generated at subscription time // so that the new concurrency value is actually used defer(() => source.pipe( mergeMap( i => // this is just a simulation of a an inner Observable emitting something interval(100).pipe( delay(100), map(j => `Observable of ${i} and ${j}`), take(10) ), myConcurrency ) ) ) ) ) .subscribe({ next: data => console.log(data) }); 会完成您的工作。

相关问题