Home >Backend Development >Golang >How to install golang on mac
How to install golang on mac: 1. Enter the GO language official, then download the package file, and install Go according to the prompts; 2. Install the Go distribution package to "/usr/local/go"; 3. Change " /usr/local/go/bin" directory is placed in the PATH environment variable; 4. Edit "~/.zshrc" and modify the configuration to "vim ~/.zshrc export GOROOT="/usr/local/go"... "; 5. Just test the installed GO environment.
The operating environment of this tutorial: macOS10.15.1 system, GO version 1.13, macbook pro 2020 computer.
How to install golang on mac?
Build GO development environment on macOS
First of all, you must be able to surf the Internet scientifically
GO language official:https://golang.google.cn/dl/
GO development environment installation documentation: https://golang.google. cn/doc/install
macOS installation package installation
1. Install Go tools
If you To upgrade from an older version of Go, you must first delete the existing version.
2. macOS package installer
Download the package file, open it, and follow the prompts to install Go. This package installs the Go distribution to /usr/local/go.
Before configuring environment variables:
3. Configure GO development Environment variables
This package should put the /usr/local/go/bin directory in the PATH environment variable. For the changes to take effect, you may need to restart any open terminal sessions.
Setting GOPATH: https://github.com/golang/go/wiki/SettingGOPATH
Edit ~/.zshrc, edit and save the following configuration
vim ~/.zshrc
export GOROOT="/usr/local/go"
export GOPATH=" /Users/zaneli/go"
export GOBIN="$GOROOT/bin"
export PATH="$PATH:$GOBIN"
source ~/.zshrc
Test the installed GO environment
Check that Go is installed correctly by setting up a workspace and building a simple program ,As follows.
Create your workspace directory, $HOME/go. (If you wish to use a different directory, you will need to set the GOPATH environment variable.)
Next, make the directory src/hello located in your workspace and create a file named hello in that directory. Like this:
package mainimport "fmt"func main() {
fmt.Printf("hello, world\n")}
##Test result
Perfect! Recommended learning: "go video tutorial"
The above is the detailed content of How to install golang on mac. For more information, please follow other related articles on the PHP Chinese website!