1.GOPATH
编译go文件前必须要先指定GOPATH目录,可以用export命令设置临时环境变量:
export GOPATH=/PATH/
也可以在环境变量配置文件(/etc/profile或个人目录下面的.bashrc)里面配置固定的值。
2.GO版本切换
为了适应不同的源码编译环境,可以灵活切换不同的go版本。通过安装gvm来实现,gvm的Github仓库点击这里 。
1.安装gvm:
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
2.gvm命令使用
]# gvm
Usage: gvm [command]
Description:
GVM is the Go Version Manager
Commands:
version - print the gvm version number
get - gets the latest code (for debugging)
use - select a go version to use (--default to set permanently)
diff - view changes to Go root
help - display this usage text
implode - completely remove gvm
install - install go versions
uninstall - uninstall go versions
cross - install go cross compilers
linkthis - link this directory into GOPATH
list - list installed go versions
listall - list available versions
alias - manage go version aliases
pkgset - manage go packages sets
pkgenv - edit the environment for a package set
3.安装对应版本的go软件包
这里以安装go1.16为例:
gvm install go1.16
4.切换go版本
gvm use go1.16
注意事项:
使用gvm的go软件包后,会自动使用默认的GOPATH,如
]# echo $GOPATH
/root/.gvm/pkgsets/go1.16/global
评论前必须登录!
注册