Golang installation and configuration environment

Installation golang:

Download the installation package, domestic Address: https://golang.google.cn/dl/

$ sudo tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz  //解压

Add the environment variable file, edit / etc / profile or $ HOME / .profile or /etc/profile.d/ directory

$ 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变量

View golang Version:

$ go version
go version go1.12.5 linux/amd64

View GOROOT

$ go env GOROOT
/usr/local/go

View GOPATH

$ echo $GOPATH
/
/work/wks_golang

demo test

In / work / wks_golang directory, create src/hello, create hello.go:

package main
import "fmt"
func main() {
    fmt.Printf("hello, world\n")
}

Use go tool to build:

$ 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

Let ZSH supports auto-completion

Is there golang plug-in to view the oh-my-zsh in

$ ls ~/.oh-my-zsh/plugins/golang/
$ vi ~/.zshrc

Modify ~/.zshrc, find an array of plugins to add:

plugins=(... golang)

Official website set GOPATH Guide

GOPATHAfter go1.8 default is $HOME/gomay be set according to the situation.

Scene 1 - Bash

Modify ~/.bash_profile, add

export GOROOT=$HOME/go
export GOPATH=$HOME/go

Enable bring it into force

source ~/.bash_profile

Scene 2 - Zsh

Modify ~/.zshrcadd:

export GOPATH=$HOME/go

Enable bring it into force

source ~/.zshrc

Guess you like

Origin blog.csdn.net/weixin_33777877/article/details/90911914