Home >Backend Development >Golang >How to install golang mac
Golang is a simple, fast, safe and efficient concurrency programming language. It is available on various operating systems, including macOS. In this article, we will discuss how to install Golang on macOS.
1. Download Golang
Before starting the installation, you need to download the latest version of Golang from https://golang.org/dl/. Golang installation files are usually less than 100MB in size, so the download speed should be fast.
2. Install Golang
mkdir $HOME/go
Next, open the .bash_profile file with the following command:
open -e $HOME/.bash_profile
In the opened file, add the following content at the end:
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bash_profile
Next, restart the terminal .
go version
If the command returns the currently running Golang version number, the installation is successful.
3. Run the first program
Next, we will create a simple "Hello, World!" program and run it. Enter the following command in the terminal:
mkdir $HOME/go/src/hello
cd $HOME/go/src/hello
echo 'package main
import "fmt "
func main() {
fmt.Println("Hello, World!")
}' > hello.go
Compile and run the program with the following command:
go run hello. go
Terminal output is as follows:
Hello, World!
This is the successful running of your first Golang program. Congratulations!
Summary
Golang is a very popular programming language, especially suitable for writing relatively small applications. Installing it on macOS is very simple and can be done easily even if you are a newbie. Just follow the steps provided in this article, and you can easily install Golang on the macOS platform and start writing your own programs.
The above is the detailed content of How to install golang mac. For more information, please follow other related articles on the PHP Chinese website!