Home  >  Article  >  Backend Development  >  brew install golang

brew install golang

WBOY
WBOYOriginal
2023-05-22 14:55:371917browse

Under Mac OS system, it is very convenient to use brew (Homebrew) to install golang, which only requires a few simple steps.

Step 1: Install brew

If you have already installed brew, you can skip this step. If you have not installed brew, please follow the steps below:

  1. Open the terminal
  2. Enter the following command and press Enter:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. Wait for the installation to complete.

Step 2: Install golang

  1. Open the terminal
  2. Enter the following command and press Enter:
brew install go
  1. Wait for the installation to complete.
  2. Verify whether golang is installed successfully. Enter the following command in the terminal and press Enter:
go version

If you see the following output, it means you have successfully installed golang:

go version go1.x.x darwin/amd64

Step 3: Configure the environment Variables

  1. Open Terminal
  2. Enter the following command and press Enter:
vi ~/.bash_profile
  1. In the open file, add the following code:
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

The above code sets the GOPATH to the go folder under your home directory and adds the path to the Go binary to your PATH environment variable.

  1. Press the ESC key, enter: wq to save and exit.
  2. Enter the following command in the terminal and press Enter to make the configuration file take effect:
source ~/.bash_profile

Now, you have successfully installed golang and can do it in the command line tool use.

Summary:

Using brew to install golang is one of the simplest and fastest methods under Mac OS systems. The installation steps are very simple, with only three steps, you can start writing code in golang. At the same time, when configuring environment variables, set GOPATH to the go folder in your home directory, so that all your Go projects can be placed in one place for easy management and maintenance.

The above is the detailed content of brew install golang. 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
Previous article:golang request forwardNext article:golang request forward