Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure macOS in go development environment

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail how to configure macOS in the go language development environment. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Macos installs the go language development package

The first step in configuring the development environment for the go language is to download the development package from the go official website download page.

MacOS needs to download the pkg suffix file

The macOS and iOS operating system Apple packages use the .pkg extension and internally use the Xar format.

Image

Mac OS's Go language development kit is in .pkg format. Double-click the installation package we downloaded to start the installation, and click "continue" all the way.

Image

The installation package is installed by default in the / usr/local directory.

Image

The structure of this directory follows the GOPATH rules, and this concept will be mentioned in later chapters. The meaning of each folder in the directory is shown in the following table.

Api: the api changes vary from version to release.

Bin:go source package compiled by the compiler (go), documentation tool (godoc), formatting tool (gofmt).

Doc: English version of the go document.

Misc: files for miscellaneous purposes, such as compilation of the Android platform, submission hooks of git, etc.

Pkg:linux platform compiled intermediate files.

Src: source code of the standard library.

Test: test cases.

Image

After the installation is complete, run go version on the terminal. If a message similar to the following is displayed, the installation is successful.

»go version jackson@192

Go version go1.13.6 darwin/amd64

Set the GOPATH environment variable

Before we start writing the go project code, we need to configure the environment variables.

Edit ~ / .bash_profile (run vim ~ / .bash_profile in the terminal) to add the following line of code (if you can't find .bash _ profile, just create one yourself).

Note that the path to gopath can also be specified by yourself, here is $HOME/go.

HOME` View the specific path

Export GOPATH=$HOME/go

Save and exit your editor. Then run the following command in the terminal to make the above command take effect immediately.

Source / .bash_profile

GOROOT is the path to the installation directory of the Go package, and the default environment variable is automatically configured in / usr/local/go. It can be set in the bash_profile file.

Export GOROOT=/usr/local/go

Then save and exit the editor and run the source ~ / .bash_profile command.

Once the environment variable is set, you can test it by entering the go env command on the command line.

»go env jackson@192

GO111MODULE= ""

GOARCH= "amd64"

GOBIN= ""

GOCACHE= "/ Users/jackson/Library/Caches/go-build"

GOENV= "/ Users/jackson/Library/Application Support/go/env"

GOEXE= ""

GOFLAGS= ""

GOHOSTARCH= "amd64"

GOHOSTOS= "darwin"

GONOPROXY= ""

GONOSUMDB= ""

GOOS= "darwin"

GOPATH= "/ Users/jackson/go"

GOPRIVATE= ""

GOPROXY= "direct"

GOROOT= "/ usr/local/go"

On how the go language development environment configuration macOS to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report