社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
下载安装包,国内地址:https://golang.google.cn/dl/
$ sudo tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz //解压
添加环境变量,修改/etc/profile 或$HOME/.profile或/etc/profile.d/目录的文件
$ sudo vi /etc/profile.d/brianconfig.sh //添加以下内容
export GOROOT=/usr/local/go //定义GOROOT
export PATH=$PATH:/usr/local/go/bin // 添加go/bin到系统环境变量PATH中
export GOPATH=/work/wks_golang //添加GOPATH变量
查看golang版本:
$ go version
go version go1.12.5 linux/amd64
查看GOROOT
$ go env GOROOT
/usr/local/go
查看GOPATH
$ echo $GOPATH
/
/work/wks_golang
在/work/wks_golang目录内,新建 src/hello
, 创建hello.go
:
package main
import "fmt"
func main() {
fmt.Printf("hello, worldn")
}
使用go tool构建:
$ cd ./src/hello
$ go build
The command above will build an executable named hello in the directory alongside your source code. Execute it to see the greeting:
$ ./hello
hello, world
查看oh-my-zsh中是否有golang插件
$ ls ~/.oh-my-zsh/plugins/golang/
$ vi ~/.zshrc
修改~/.zshrc
,找到plugins数组添加:
plugins=(... golang)
GOPATH
在go1.8后默认是$HOME/go
,也可以根据情况设定。
修改 ~/.bash_profile
,添加
export GOROOT=$HOME/go
export GOPATH=$HOME/go
启用使之生效
source ~/.bash_profile
修改~/.zshrc
添加:
export GOPATH=$HOME/go
启用使之生效
source ~/.zshrc
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!