Home > Backend Development > Golang > Install golang under mac

Install golang under mac

WBOY
Release: 2023-05-14 18:56:07
Original
1073 people have browsed it

With the continuous development and widespread application of Go language, more and more developers choose to use Go to build applications. If you are a Mac user and want to install the Go language on your computer, this article will provide you with some easy-to-understand steps and guidance to complete the installation easily.

Preparation before installation

Before installing Go, we need to make the following preparations:

  1. Download the Go installation package

Open the official website (https://golang.org/dl/) and select the latest version of the installation package under the macOS system to download. It is recommended to choose the installation package in compressed package (tar.gz) format and decompress it after downloading.

  1. Configuring environment variables

In macOS, we can use the Terminal to configure Go environment variables. Open a terminal and enter the following command in the command line:

nano ~/.bash_profile
Copy after login
Copy after login

Then add the following content to the opened file:

export PATH=$PATH:/usr/local/go/bin
Copy after login
Copy after login

Save the file and exit.

  1. Check the installation

After completing the installation and configuring the environment variables, we need to check whether Go is installed normally. Enter the following command in the terminal:

go version
Copy after login
Copy after login

If the output is similar to the following, it means that Go has been successfully installed:

go version go1.17 darwin/amd64
Copy after login
Copy after login

Detailed explanation of the installation process

Next we will According to the above preparation steps, we will explain step by step how to install Go language on macOS system.

Step 1: Download the installation package

First, we need to open the official website (https://golang.org/dl/) and find the latest version of the installation under the macOS system on the page package to download. It is recommended to choose the installation package in compressed package (tar.gz) format, because the installation package in this format is relatively small and can save some download time and network traffic.

After the download is completed, we need to find the location of the downloaded file, and then double-click to open the compressed package. After decompression, we can see that the decompressed folder contains a go folder and some other files.

Step 2: Move the folder to the specified location

In order for Go to run normally, we need to move the unzipped folder to the specified location. Open the terminal and use the following command to enter the current user's home directory:

cd ~
Copy after login

Create a new folder in the home directory to store Go language-related files:

mkdir go
Copy after login

Then unzip Move the final folder to the folder you just created:

mv Downloads/go ~/go
Copy after login

Note: Downloads here is the download folder on my computer. If your download folder has a different name, please make the corresponding change based on the actual situation. Revise.

Step 3: Configure environment variables

In macOS, we need to configure environment variables to allow Go to run normally. Open a terminal and enter the following command in the command line:

nano ~/.bash_profile
Copy after login
Copy after login

Then add the following content to the opened file:

export PATH=$PATH:/usr/local/go/bin
Copy after login
Copy after login

Save the file and exit.

Step 4: Check the installation

After completing the installation and configuring environment variables, we need to check whether Go is installed normally. Enter the following command in the terminal:

go version
Copy after login
Copy after login

If the output is similar to the following, Go has been successfully installed:

go version go1.17 darwin/amd64
Copy after login
Copy after login

Summary

Through the above steps, we can Easily install Go language on Mac system, and perform environment variable configuration and installation check.

Some points to note when installing Go:

  1. The downloaded installation package must match your system version.
  2. After decompression, place the folder in the specified location.
  3. Don’t forget to configure environment variables.
  4. After the installation is completed, you need to check whether the installation was successful.

I hope this article can provide useful help and guidance for Mac users when installing the Go language.

The above is the detailed content of Install golang under mac. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template