golang-v1127-安装

49次阅读

共计 1950 个字符,预计需要花费 5 分钟才能阅读完成。

下载安装包

国外的

https://golang.org/dl/

国内的

https://studygolang.com/dl

安装

mac os

  1. 直接点击go1.12.7.darwin-amd64.pkg,进入图形界面安装。
  2. ~/.zshrc 中,添加环境变量(如果是别的 sh,请在别的 sh 中配置)

    #GOROOT
    export GOROOT=/usr/local/go/
    
    #GOPATH  go 项目路径
    export GOPATH=$HOME/workspace/project
    
    #GOPATH bin
    export PATH=$PATH:$GOPATH/bin
    
    #GOPATH root bin
    export PATH=$PATH:$GOROOT/bin
  3. source ~/.zshrc
  4. 验证

    # go version
    go version go1.12.7 darwin/amd64
    # go env
    GOARCH="amd64"
    GOBIN=""GOCACHE="/Users/manshu/Library/Caches/go-build"GOEXE=""
    GOFLAGS=""GOHOSTARCH="amd64"GOHOSTOS="darwin"GOOS="darwin"GOPATH="/Users/manshu/workspace/project"GOPROXY="https://goproxy.io"GORACE=""
    GOROOT="/usr/local/go"
    GOTMPDIR=""GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"GCCGO="gccgo"CC="clang"CXX="clang++"CGO_ENABLED="1"GOMOD=""
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""CGO_CXXFLAGS="-g -O2"CGO_FFLAGS="-g -O2"CGO_LDFLAGS="-g -O2"PKG_CONFIG="pkg-config"GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wp/w879p9h15x983cgrs5cz25rc0000gn/T/go-build153405912=/tmp/go-build -gno-record-gcc-switches -fno-common"

linux

  1. 解压 tar xzvf go1.12.7.linux-amd64.tar.gz -C /usr/lib/
  2. ~/.bashrc 中,添加环境变量(如果是别的 sh,请在别的 sh 中配置

    #GOROOT
    export GOROOT=/usr/lib/go
    
    #GOPATH go 项目路径
    export GOPATH=/root/gocode
    
    #GOPATH bin
    export PATH=$PATH:$GOPATH/bin
    
    #GOPATH root bin
    export PATH=$PATH:$GOROOT/bin
  3. source ~/.bashrc
  4. 验证

    [root@compute84 bin]# go version
    go version go1.12.7 linux/amd64
    [root@compute84 bin]#
    [root@compute84 bin]# go env
    GOARCH="amd64"
    GOBIN=""GOCACHE="/root/.cache/go-build"GOEXE=""
    GOFLAGS=""GOHOSTARCH="amd64"GOHOSTOS="linux"GOOS="linux"GOPATH="/root/gocode"GOPROXY="https://goproxy.io"GORACE=""
    GOROOT="/usr/lib/go"
    GOTMPDIR=""GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"GCCGO="gccgo"CC="gcc"CXX="g++"CGO_ENABLED="1"GOMOD=""
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""CGO_CXXFLAGS="-g -O2"CGO_FFLAGS="-g -O2"CGO_LDFLAGS="-g -O2"PKG_CONFIG="pkg-config"GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build670179021=/tmp/go-build -gno-record-gcc-switches"

正文完
 0