Home  >  Article  >  Backend Development  >  This article explains how to install Golang in Linux system

This article explains how to install Golang in Linux system

PHPz
PHPzOriginal
2023-04-11 09:16:531692browse

Golang, also called Go language, is a programming language with extremely high operating efficiency. It has been sought after by many developers because of its simple syntax and strong parallel processing capabilities. In Linux systems, the installation of Golang is as easy and simple as other software. This article will explain how to install Golang in Linux system.

Step 1: Download the installation package

Before starting to install Golang, you need to enter the Golang official website https://golang.org/dl/ and select the version to be installed, such as the latest version Version 1.17.2, and then select the appropriate operating system. After selecting Linux, the download link for the corresponding version will appear.

You can use the wget command to download the corresponding installation package. For example, execute the following command:

wget https://golang.google.cn/dl/go1.17.2.linux-amd64.tar.gz

The installation package of the latest version of Golang can be downloaded to the current directory.

Step 2: Decompress the installation package

After the download is complete, use the following commands in the terminal to decompress the installation package, for example, execute the following command:

sudo tar -C /usr/local -xzf go1.17.2.linux-amd64.tar.gz

Decompress the installation package Unzip it to the /usr/local directory. If you do not want to extract to this directory, you can replace /usr/local with the directory you want to extract.

Step 3: Set environment variables

In order to use Golang, you need to add it to the system environment variables. You can set it in the following two ways:

  1. Add environment variables in /etc/profile so that all users can access Golang

Use vim or other editors Open /etc/profile, and then add the following content at the end:

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

Among them, the GOROOT variable points to the Golang installation path, the GOPATH variable is the customized working path, and the PATH variable is the system environment variable.

  1. Add environment variables in the current user’s ~/.bashrc file

Use vim or other editors to open the current user’s ~/.bashrc file, and then add the following Content:

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

After saving, you can use the source command to make the environment variables take effect immediately. For example, execute the following command:

source ~/.bashrc

Step 4: Verify that the installation is complete

Complete the above steps Finally, you can enter the following command in the terminal to verify whether Golang is installed successfully:

go version

If the installation is successful, the corresponding version number will be output.

At this point, Golang has been successfully installed in the Linux system, and you can start using its various functions for development. If you need to update or uninstall Golang later, execute the relevant commands in the above directory to complete.

The above is the detailed content of This article explains how to install Golang in Linux system. 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