Home >Backend Development >Golang >How to install golang on mac

How to install golang on mac

藏色散人
藏色散人Original
2023-03-25 11:36:166248browse

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.

How to install golang on mac

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:golang.google.cn/dl/

GO development environment installation documentation: golang.google. cn/doc/in

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.

How to install golang on mac

How to install golang on mac

Before configuring environment variables:

How to install golang on mac

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: github.com/golang/go/wi

How to install golang on mac

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

After the environment variable is configured :

How to install golang on mac

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")}
How to install golang on mac

##Test result

How to install golang on mac
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn