- 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:
-
- Add it to your shell startup script, .bashrc. This will set the variable every time you start the Terminal.
- Run this to ensure that GOPATH is set whenever you open future Terminal/shell sessions:
echo "export GOPATH=$HOME" >> $HOME/.bashrc
-
- 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.
推薦閱讀
- 西去東來(lái):沿絲綢之路數(shù)學(xué)知識(shí)的傳播與交流
- 卓越的課件如何做(數(shù)學(xué)篇)
- 武俠數(shù)學(xué)
- 概率論與數(shù)理統(tǒng)計(jì)
- 這才是好看的數(shù)學(xué)
- 數(shù)學(xué)建模33講:數(shù)學(xué)與繽紛的世界
- 高等數(shù)學(xué)(下冊(cè))
- 越玩越聰明的印度數(shù)學(xué)和孫子算經(jīng)
- 硅谷工程師爸爸的超強(qiáng)數(shù)學(xué)思維課:激發(fā)孩子的數(shù)感天賦
- CAE分析大系:ANSYS疑難問(wèn)題實(shí)例詳解
- 神機(jī)妙算:一本關(guān)于算法的閑書(shū)
- 圖像處理的分?jǐn)?shù)階微積分方法
- 數(shù)學(xué)要素(全彩圖解 + 微課 + Python編程)
- 現(xiàn)代啟發(fā)式優(yōu)化方法及其應(yīng)用
- 12堂魔力數(shù)學(xué)課