Home  >  Article  >  Backend Development  >  mac golang tar installation

mac golang tar installation

WBOY
WBOYOriginal
2023-05-10 09:10:36736browse

Under Mac OS X system, we can use tar package to install Go language. tar is a tool that can compress and decompress files. Most Linux and Unix systems have tar packages installed by default.

The following are the detailed steps for installing Go language using tar package under Mac OS X system.

Step 1: Download the Go language installation package

First, we need to download the Go language installation package from the official website, the address is: https://golang.org/dl/

We need to download the installation package suitable for Mac OS X system and select the corresponding installation package according to our own system version. For example, if your system version is Mac OS X 10.14 (Mojave), you can select the go1.12.7.darwin-amd64.pkg installation package.

Step 2: Unzip the installation package

Place the downloaded installation package in any folder, then open the Terminal and enter the folder.

Run the following command to decompress the installation package:

tar -C /usr/local -xzf go1.12.7.darwin-amd64.tar.gz

This command will Unzip the Go language installation package to the /usr/local directory.

Step 3: Set environment variables

We next need to set the Go language environment variables so that we can use Go language commands in the terminal.

Open Terminal and use the following command to edit the .bash_profile file:

vi ~/.bash_profile

In the open editor, press "i" key to enter insert mode.

Add the following code:

export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

Explanation:

GOPATH: The working directory of the Go language, which can be set according to your own needs, for example: $HOME/go.

PATH: System environment variable. Here, the Go language command path is added to the PATH variable to facilitate us to use Go language commands in the terminal.

After adding, press the "Esc" key to exit the insert mode, then enter the ":wq" command to save and exit the editor.

Execute the following command to make the environment variable setting take effect:

source ~/.bash_profile

Step 4: Test installation

Now, we can Test whether the Go language has been successfully installed. Execute the following command in the terminal:

go version

If the version information of the Go language is successfully output, it means that the Go language has been successfully installed. If a "command not found" error message is displayed, the problem requires further investigation.

Summary

It is very simple to install Go language on Mac OS X system using tar package. You only need to download the installation package, unzip it, set environment variables, and test to complete the entire process. If any problems occur, you can view error messages in the terminal to help us troubleshoot the problem faster.

The above is the detailed content of mac golang tar installation. 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