go语言环境的安装配置

本文详细介绍了Go语言在Windows上的安装步骤,包括下载、安装、路径选择以及环境变量配置。通过CMD验证安装成功,并展示了`go env`的输出信息,强调了GOPATH的重要性。此外,还提供了简单的Go命令行使用说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

go语言官网:https://golang.google.cn/

go中文网:https://studygolang.com/dl

下载相应的软件包

在这里插入图片描述

现在最新版本是1.18版本

在这里插入图片描述

你也可以使用1.17版本,都可以。

安装:

在这里插入图片描述

双击开始安装

在这里插入图片描述

选择合适的路径安装

在这里插入图片描述
我的安装路径: 在这里插入图片描述
在这里插入图片描述

不要忘记你安装的路径,所以尽可能用个好记的名字

开始安装

在这里插入图片描述

点击install就开始安装了。

测试

安装完成之后开始测试:

打开CMD 输入go
在这里插入图片描述

查看版本使用:version

在这里插入图片描述

配置变量 GOPATH

GOPATH 是 Go语言中使用的一个环境变量,它使用绝对路径提供项目的工作目录(workspace)。

GOPATH下创建src文件夹,即存放Go项目代码的位置。

搜索:在这里插入图片描述

在这里插入图片描述
新建一个目录,用来存放后期写的代码:
在这里插入图片描述
GoWork有三个目录

在这里插入图片描述
src // 存储go的源代码(需要我们自己手动创建)
pkg // 存储编译后生成的包文件 (自动生成)
bin // 存储生成的可执行文件(自动生成)

配置好后,查看环境变量:

C:\Users\xinsz08>go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\xinsz08\AppData\Local\go-build
set GOENV=C:\Users\xinsz08\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=E:\GoWork\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\GoWork
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=E:\golang_install_win
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=E:\golang_install_win\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17.5
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=D:\Temp\go-build1159393017=/tmp/go-build -gno-record-gcc-switches

其中: GOROOT表示开发包的安装目录

补充:

执行完go之后出来的参数

C:\Users\xinsz08>go
Go is a tool for managing Go source code.

Usage:

        go <command> [arguments]

The commands are:

        bug         start a bug report   ## bug 报告
        build       compile packages and dependencies## 构建包和依赖项 
        clean       remove object files and cached files  ## 清楚缓存文件和对象
        doc         show documentation for package or symbol
        env         print Go environment information
        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing source
        get         add dependencies to current module and install them
        install     compile and install packages and dependencies  ## 安装编译依赖项
        list        list packages or modules
        mod         module maintenance
        run         compile and run Go program  ## 运行go程序
        test        test packages
        tool        run specified go tool
        version     print Go version   ## 打印版本
        vet         report likely mistakes in packages

Use "go help <command>" for more information about a command.

Additional help topics:

        buildconstraint build constraints
        buildmode       build modes
        c               calling between Go and C
        cache           build and test caching
        environment     environment variables
        filetype        file types
        go.mod          the go.mod file
        gopath          GOPATH environment variable
        gopath-get      legacy GOPATH go get
        goproxy         module proxy protocol
        importpath      import path syntax
        modules         modules, module versions, and more
        module-get      module-aware go get
        module-auth     module authentication using go.sum
        packages        package lists and patterns
        private         configuration for downloading non-public code
        testflag        testing flags
        testfunc        testing functions
        vcs             controlling version control with GOVCS

Use "go help <topic>" for more information about that topic.


C:\Users\xinsz08>

总结

go相对来说,安装比较简单,傻瓜式安装,在Linux和mac的安装大家找一下其他资料。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

互联网老辛

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值