Install GoLang using Brew
This article describes how to install GoLang using Brew on Linux or macOS.
Install GoLang using Brew
brew installs missing packages in Linux and macOS. It makes it easy to install GoLang on Linux or macOS.
Follow the steps below to install GoLang on Linux or macOS using the brew command.
-
First, brew should be installed; if not already installed, run the command mentioned below. It may require administrator privileges and take a while.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
We have to run a few more commands to complete the brew installation. Run the following three commands to add Homebrew to your PATH and make sure the path is correct.
In our example:
```bash echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /home/sheeraz/.profile echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /home/sheeraz/.profile eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" ``` To install Homebrew's dependencies, use the following commands: ```bash sudo apt-get install build-essential ``` -
After installing brew, the next step is to update it and install Golang. Run the following commands:
brew update && brew install golang
-
The command above will install GoLang using brew command; the next step is to set up the workspace. We use the path $HOME/go to set up our workspace and run the following command:
mkdir -p $HOME/go/{bin,src,pkg}
-
One more important step is to set up the environment for Golang; to do this, we need to add the following information to our .bashrc file:
Now we can use GoLang and create a project with a src directory in the go path.export GOPATH=$HOME/go export GOROOT="$(brew --prefix golang)/libexec" export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Getting a string representation of a structure in Go
Publish Date:2025/04/15 Views:63 Category:Go
-
Go allows us to serialize data from structures using a variety of simple standard methods. Converting a structure to a string using String method in Go The GoLang package String helps implement simple functions to manipulate and edit UTF-8
Convert JSON to struct in Go
Publish Date:2025/04/15 Views:126 Category:Go
-
This article describes how to convert JSON to struct in GoLang . Convert JSON to Struct using Unmarshal method in Go The encoding/json package of the Go language provides a function Unmarshal to convert JSON data into byte format. This func
在 Golang 中使用 If-Else 和 Switch Loop Inside HTML 模板
Publish Date:2023/04/27 Views:104 Category:Go
-
本篇文章介绍了在 Golang 的 HTML 模板中使用 if-else 和 switch 循环。因此,只要输出是 HTML,就应该始终使用 HTML 模板包而不是文本模板。
Golang 中的零值 Nil
Publish Date:2023/04/27 Views:185 Category:Go
-
本篇文章介绍 nil 在 Golang 中的含义,nil 是 Go 编程语言中的零值,是众所周知且重要的预定义标识符。
Golang 中的 Lambda 表达式
Publish Date:2023/04/27 Views:699 Category:Go
-
本篇文章介绍如何在 Golang 中创建 lambda 表达式。Lambda 表达式似乎不存在于 Golang 中。 函数文字、lambda 函数或闭包是匿名函数的另一个名称。
在 Go 中捕获 Panics
Publish Date:2023/04/27 Views:104 Category:Go
-
像错误一样,Panic 发生在运行时。 换句话说,当您的 Go 程序中出现意外情况导致执行终止时,就会发生 Panics。让我们看一些例子来捕捉 Golang 中的Panics。
在 Go 中使用断言
Publish Date:2023/04/27 Views:593 Category:Go
-
本篇文章介绍了 assert 在 GoLang 中的使用。在 Go 语言中使用断言:GoLang 不提供对断言的任何内置支持,但我们可以使用来自 Testify API 的广泛使用的第三方包断言。