Home >Backend Development >Golang >Golang deployment and installation guide for setting up a Go development environment
In order to facilitate developers to quickly set up a Go language development environment, we will introduce in detail how to deploy and install Golang on different operating systems, and how to configure the Go programming environment, with specific details. code example.
For Windows users, installing and configuring the Go language environment is very simple. Just follow the following steps:
During the installation process, select the installation directory and add the installation path of the Go language to the system environment variable. You can check whether Go is successfully installed by running the following command:
go version
Configure the GOPATH (working directory) and GOROOT (Go language installation path) environment variables. Open a command line window and execute the following command:
setx GOPATH C:path oyourworkspace setx GOROOT C:Go
After completing the above steps, you can create a simple Go project, such as the HelloWorld program. Create a new file hello.go
and enter the following code:
package main import "fmt" func main() { fmt.Println("Hello, World!") }
Enter the directory where hello.go
is located on the command line and execute The following command compiles and runs the program:
go run hello.go
Hello, World!
, it means that the Go language environment has been successfully installed and configured. For macOS users, installing and configuring the Go language development environment is equally simple and fast. The following are the specific steps:
Execute the following command in the terminal to install Golang using Homebrew:
brew install golang
After the installation is complete, execute the following command Check the Go language version:
go version
Configure the GOPATH and GOROOT environment variables. Execute the following command in the terminal:
export GOPATH=/path/to/your/workspace export GOROOT=/usr/local/opt/go/libexec
Create a simple Go project and write the HelloWorld program. Also create a new hello.go
file and enter the following code:
package main import "fmt" func main() { fmt.Println("Hello, World!") }
Enter the directory where hello.go
is located in the terminal and run the program:
go run hello.go
Hello, World!
, it means that the Go language environment is successfully configured under macOS. For Linux users, the installation and configuration of Golang is also very simple and clear. The following are detailed steps:
Execute the following command in the terminal and use apt or yum package manager to install Golang:
sudo apt-get update sudo apt-get install golang
After the installation is completed , execute the following command to check the Go language version:
go version
Similarly, configure the GOPATH and GOROOT environment variables. Execute the following command in the terminal:
export GOPATH=/path/to/your/workspace export GOROOT=/usr/lib/go
Create a simple Go project and write the HelloWorld program. Also create a new hello.go
file and enter the following code:
package main import "fmt" func main() { fmt.Println("Hello, World!") }
Enter the directory where hello.go
is located in the terminal and run the program:
go run hello.go
Hello, World!
, it means that the Go language environment is successfully configured under Linux. Through the above steps and sample code, we have introduced in detail the steps to deploy and configure the Golang development environment on Windows, macOS and Linux platforms. I hope it can help developers who are learning and using Go language to quickly get started and enjoy the charm of Go language.
The above is the detailed content of Golang deployment and installation guide for setting up a Go development environment. For more information, please follow other related articles on the PHP Chinese website!