duanri1904
2016-11-27 03:56
浏览 575
已采纳

golang环境变量存储在哪里?

I am just started learning golang on Windows 7.

With go env, I got this:

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\Workbench\Go
set GORACE=
set GOROOT=C:\DevTools\Go
set GOTOOLDIR=C:\DevTools\Go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1

Then I checked with echo %envVar% in the command line, I found env vars like:

GOPATH
GOROOT

But others are not found.

So where are they stored? Some hidden configuration file?

图片转代码服务由CSDN问答提供 功能建议

我刚刚开始在Windows 7上学习golang。

使用 >转到环境,我得到了:

  set GOARCH = amd64 
set GOBIN = 
set GOEXE = .exe 
set GOHOSTARCH = amd64 
set GOHOSTOS = windows  
set GOOS = windows 
set GOPATH = E:\ Workbench \ Go 
set GORACE = 
set GOROOT = C:\ DevTools \ Go 
set GOTOOLDIR = C:\ DevTools \ Go \ pkg \ tool \ windows_amd64 
set CC = gcc  
set GOGCCFLAGS = -m64 -mthreads -fmessage-length = 0 
set CXX = g ++ 
set CGO_ENABLED = 1 
   
 
 

然后我用 echo%进行了检查 envVar%在命令行中,我发现了env vars,例如:

  GOPATH 
GOROOT 
   
 
 

但是找不到其他人。

那么它们存储在哪里? 一些隐藏的配置文件?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doupin1073 2016-11-27 04:33
    已采纳

    Those are just the defaults for your platform. Think of them as stored in the go.exe executable itself.

    You can override them by setting them to something else like any other env var.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doulan6245 2016-11-27 05:41

    Like what @David Budworth says, those variables are the defaults for your platform.

    Most of case we change $GOPATH and $GOROOT variables. For example in my PC i use export GOPATH=/home/user/go and yours may be different from mine.

    Otherwise, if you look to find where other variables are stored you need to look at /usr/lib/go-1.6/src (sorry i'm using Ubuntu right now with go 1.6 and i don't know the path directory of go in Windows), you'll find there many bash scripts used when you built your go executable.

    For example:

    in the file: make.bash you'll see: $GROOT was declared there and used to build the final go executable:

    export GOROOT="$(cd .. && pwd)"
    

    I saw, also, your comments about GOTOOLDIR and how it knows your installation location of go in your box. I would say, that the source code of go have the answer and you can find it here:

    // ToolDir is the directory containing build tools.
    var ToolDir = filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
    

    Edit: I found this good article about building go: How GO uses to build itself

    PS: Sorry for my english. I'm not a native english speaker.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题