Home >Backend Development >Golang >Guide to setting up the operating environment of Golang under Mac system
Guide to setting up the Golang operating environment under Mac system
Golang, also known as the Go language, is an open source programming language developed by Google. It has the characteristics of high concurrency, fast compilation speed, and complete tool chain, so it is very popular in the field of software development. If you are a Mac user and want to set up a Golang running environment on a Mac system, the following guide will help you complete the process.
First, you need to download the Golang installation package for Mac system from the official website https://golang.org/dl/. Choose the installation package appropriate for your Mac version, which is usually provided in .pkg format.
After the download is complete, double-click the Golang installation package to install. Follow the installation wizard prompts to install Golang into the directory of your choice. After the installation is complete, you need to configure Golang’s environment variables.
Open a terminal window and enter the following command to edit the ~/.bash_profile file:
$ nano ~/.bash_profile
Add the following content at the end of the file:
export PATH=$PATH:/usr/local/go/bin
Save and exit the editor. Next, load the modified environment variable configuration:
$ source ~/.bash_profile
Enter the following command in the terminal to check the Golang version information to verify whether the installation is successful:
$ go version
If the Golang version number is successfully displayed, it means the installation is correct.
Next, let’s write a simple Hello World program to verify the setup of the Golang operating environment.
Create a new file named hello.go and enter the following code:
package main import "fmt" func main() { fmt.Println("Hello, Golang!") }
After saving the hello.go file, enter the directory where the file is located in the terminal and enter the following command to run Program:
$ go run hello.go
If "Hello, Golang!" is successfully output, it means that you have successfully built and run the Golang program.
Through the above steps, you have successfully set up the Golang operating environment on the Mac system, and successfully written and run a simple Golang program. I hope this guide can help you start developing with Golang smoothly, and I wish you more achievements in learning and practice!
The above is the detailed content of Guide to setting up the operating environment of Golang under Mac system. For more information, please follow other related articles on the PHP Chinese website!