Win10+VSCode搭建GoLang开发环境
1.下载GoLang
All releases - The Go Programming Language (google.cn)
go1.20.5.windows-amd64.zip | Archive | Windows | x86-64(绿色版)
2.下载Git
Git - Downloading Package (git-scm.com)
https://github.com/git-for-windows/git/releases/download/v2.41.0.windows.1/Git-2.41.0-64-bit.exe(安装版)
3.下载VSCode
Download Visual Studio Code - Mac, Linux, Windows
Documentation for Visual Studio Code(绿色版)
4.开始配置
a.安装Git,一步步默认配置即可。
b.解压go1.20.5.windows-amd64.zip到D:\GoLang\目录下
c.解压VSCodel绿色版解压包到D:\VSCode\目录下
5.配置启动脚本
@ECHO OFF
CD /D %~dp0
SET JAVA_HOME=%CD%\java\jdk-11.0.10+9
SET GRADLE_HOME=%CD%\java\gradle-7.0
SET MAVEN_HOME=%CD%\java\apache-maven-3.8.1
SET PYTHON3_HOME=%CD%\Python373x64
SET GOROOT=D:\GoLang\go
SET GOBIN=D:\GoLang\go\bin
SET GOPATH=D:\MyProjects\GoProjects
SET PATH=%GOROOT%\bin;%GOPATH%\bin;%PYTHON3_HOME%;%PYTHON3_HOME%\Scripts;%JAVA_HOME%\bin;%MAVEN_HOME%\bin;%GRADLE_HOME%\bin;%PATH%
SET GRADLE_OPTS="-Dfile.encoding=UTF-8"
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct
go env -w GOPRIVATE=*.corp.example.com
python -m pip install --upgrade pip
CD /D "D:\DevelopmentEnvironment\Softwares\Microsoft VS Code\_"
@ECHO ON
@START "" "%CD%\Code.exe"
@EXIT
@ECHO &PAUSE
6.创建工程并运行示例代码
cmd或powershell命令行下:
>cd D:\MyProjects\GoProjects
>mkdir pkg
>mkdir src
>mkdir bin
>go work init hello
>mkdir hello
>cd hello
>go work use hello
>go mod init hello(工程名)
>echo "package main" > hello.go
用VSCode编辑hello.go:
package main
import "fmt"
func main()
{
fmt.Println("hello world!")
}
>go build
>hello.exe
hello world!
>
完成!