官术网_书友最值得收藏!

  • Go Systems Programming
  • Mihalis Tsoukalos
  • 296字
  • 2021-07-02 18:07:57

Go environment variables

The go tool can use many Unix shell environment variables dedicated to Go, including GOROOT, GOHOME, GOBIN, and GOPATH. The most important Go environment variable is GOPATH, which specifies the location of your workspace. Usually, this is the only environment variable that you will need to define when developing Go code; it is to do with the way the files of a project will be organized. This means that each project will be organized into three main directories, named src, pkg, and bin. However, many people, including me, prefer not to use GOPATH and manually organize their project files.

So, if you are a big fan of shell variables, you can put all these kinds of definitions in either .bashrc or .profile, which means that these environment variables will be active every time you log in to your Unix machine. If you are not using the Bash shell, which is the default Linux and macOS shell, then you might need to use another start up file. Check out the documentation of your favorite Unix shell to find out which file to use.

The upcoming screenshot shows part of the output of the following command, which displays all the environment variables used by Go:

$ go help environment
The output of the "go help environment" command

You can find additional information about a particular environment variable by executing the next command and replacing NAME with the environment variable that interests you:

$ go env NAME  

All these environment variables have nothing to do with the actual Go code or the execution of the program, but they might affect the development environment; therefore, if you happen to see any strange behavior while trying to compile a Go program, check the environment variables you are using.

主站蜘蛛池模板: 合山市| 龙泉市| 七台河市| 祁阳县| 界首市| 道真| 平果县| 农安县| 英德市| 台北市| 广昌县| 马尔康县| 甘谷县| 浦东新区| 郁南县| 乐东| 永泰县| 四川省| 深水埗区| 高清| 尚义县| 陈巴尔虎旗| 无棣县| 兴海县| 龙胜| 乌兰察布市| 鸡西市| 石门县| 龙山县| 襄樊市| 庆元县| 阿瓦提县| 邯郸县| 馆陶县| 体育| 富民县| 湖北省| 焦作市| 原平市| 塘沽区| 赤水市|