Mac can run golang. Due to its modular design and modularity, that is, the code is compiled and converted into the smallest possible binary form, therefore, golang does not require dependencies and supports platform independence; golang's code can be compiled on any platform and can be run on any server and compile on the application.
The operating environment of this tutorial: Windows 7 system, GO version 1.18, Dell G3 computer.
What is Go language?
Go is a procedural programming language that can be used for fast machine code compilation. It is a statically typed compiled language. It provides a concurrency mechanism that makes it easy to develop multi-core and networked machine-level programs. It is a fast, dynamically typed and interpreted language; it provides support for interfaces and type embedding.
The Go language was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson of Google, but launched as an open source programming language in 2009.
Note: The extension of the go language source code file must be .go.
golang supports cross-platform
Go language, like Java language, supports platform independence. Due to its modular design and modularity, i.e. the code is compiled and converted into the smallest possible binary form, therefore, it requires no dependencies. Its code compiles on any platform and on any server and application.
No need to use a virtual machine, the Go language code can be directly output as a binary executable file. Moreover, the Go language has its own linker and does not rely on the compiler and linker provided by any system. Therefore, the compiled binary executable file can run in almost any system environment.
mac installation golang development environment
1. Download and install
brew install go
2 .Configure environment variables
sudo vim ~/.zshrc //增加以下内容(可以不用配置goPath,直接使用mod进行项目管理,更方便,新建项目不用新建gopath,要不然下载的包在一起多个项目使用版本不一致有可能会有冲突) #go #export GOPATH=/opt/homebrew/Cellar/go/1.17.8 #export GOBIN=$GOPATH/bin #export PATH=$PATH:$GOBIN #GO module export GO111MODULE=on export GOPROXY=https://mirrors.aliyun.com/goproxy/
3. Create a new test directory
mkdir test go mod init test
4. Code test
5. Commonly used commands
go env #查看go环境变量 go mod init #项目名称 go get 地址 #下载远程依赖 go list -m all #查看项目使用的模块 go mod tidy #清除未使用的依赖
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of Can mac run golang?. For more information, please follow other related articles on the PHP Chinese website!