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

  • Security with Go
  • John Daniel Leon
  • 249字
  • 2021-06-30 19:06:42

Setting up environment variables

In order for most of the Go toolchain to work, the GOPATH environment variable must be set. The GOPATH specifies what directory you treat as your workspace. The GOPATH environment variable must be set before you can build packages. For more help and information, call the go help command in the Terminal by running this command:

go help gopath

We need to tell Go to treat our home directory as the workspace. This is done by setting the GOPATH environment variable. You can set GOPATH in three ways:

  • The first way is to set it manually each time you run the go command. Consider this example:
      GOPATH=$HOME go build hello
  • You can also set the GOPATH variable so that it stays set until you close your Terminal and the environment variable is lost:
      export GOPATH=$HOME
  • The third option is to set the GOPATH environment variable permanently as follows:
    1. Add it to your shell startup script, .bashrc. This will set the variable every time you start the Terminal.
    2. Run this to ensure that GOPATH is set whenever you open future Terminal/shell sessions:
              echo "export GOPATH=$HOME" >> $HOME/.bashrc
    1. Restart your Terminal for the changes to take effect. If you are using Zsh or an alternative shell, you will need to update the respective RC file.
Note that Go version 1.8 and greater do not require the GOPATH environment variable to be explicitly set. If no GOPATH is set, it will use $HOME/go as a default workspace.
主站蜘蛛池模板: 石嘴山市| 于都县| 四川省| 清新县| 鲁甸县| 富宁县| 罗山县| 大邑县| 虞城县| 会昌县| 溧水县| 沭阳县| 临西县| 邓州市| 安溪县| 东光县| 小金县| 沂南县| 大悟县| 日喀则市| 武城县| 高雄县| 永靖县| 宜章县| 瓮安县| 玉溪市| 开鲁县| 巴林右旗| 泾源县| 抚松县| 桂阳县| 峨山| 抚州市| 金平| 栖霞市| 义乌市| 青冈县| 富阳市| 东宁县| 岱山县| 张北县|