在WIN10系统下,安装Go语言并配置环境变量

Kate ·
更新时间:2024-09-20
· 937 次阅读

Install the Go tools Windows

The Go project provides two installation options for Windows users : a zip archive that requires you to set some environment variables and an MSI installer that configures your installation automatically.(推荐使用MSI安装包会自动配置环境变量)

MSI installer

Open the MSI file and follow the prompts to install the Go tools. By default, the installer puts the Go distribution in c:\Go.

The installer should put the c:\Go\bin directory in your PATH environment variable. You may need to restart any open command prompts for the change to take effect.

Linux

Download the archive and extract it into /usr/local, creating a Go tree in /usr/local/go. For example:

tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz

(Typically these commands must be run as root or through sudo.)

Add /usr/local/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile (for a system-wide installation) or $HOME/.profile:

export PATH=$PATH:/usr/local/go/bin Test your installation

Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.

Create your workspace directory, %USERPROFILE%\go. (If you'd like to use a different directory, you will need to set the GOPATH environment variable.)

Next, make the directory src\hello inside your workspace, and in that directory create a file named hello.go that looks like:

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

Then build it with the go tool:

C:\> cd %USERPROFILE%\go\src\hello
C:\Users\Gopher\go\src\hello> go build
go run hello.go

The command above will build an executable named hello.exe in the directory alongside your source code. 

参考资料:

https://golang.google.cn/doc/install


作者:康冕峰



环境 配置环境变量 GO 系统 win 环境变量 go语言 变量

需要 登录 后方可回复, 如果你还没有账号请 注册新账号