Home  >  Article  >  Operation and Maintenance  >  How to install golang on linux system

How to install golang on linux system

WBOY
WBOYforward
2023-05-18 16:19:201807browse

Step 1: Download Golang

Please download the version corresponding to your system from the official website (https://golang.org/dl/) Adapted installation package. The latest version of Golang is currently version 1.17.

Here, we take the officially provided Linux version of Golang as an example. The command is as follows:

wget https://golang.org/dl/go1.17.linux-amd64.tar.gz

Step 2: Unzip the downloaded file

After the download is completed, we need to unzip the downloaded Golang installation package.

Use the following command to decompress:

tar -xvf go1.17.linux-amd64.tar.gz -C /usr/local/

After this step is completed, Golang will be decompressed into the /usr/local/go directory.

Step 3: Configure environment variables

Although Golang’s executable files can be automatically added to the PATH environment variable during the installation process, other configurations still need to be completed manually. Configuration of environment variables.

We need to add the following content to the ~/.bashrc or ~/.zshrc configuration file:

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

The meaning of the above configuration items is as follows:

  • export GOPATH=$HOME/go: This configuration specifies that Golang’s working directory is $HOME/go.

  • export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin: This configuration is to add Golang commands to the system commands path to use Golang tools directly in the terminal.

Step 4: Verify the installation

After the installation is completed, we should verify whether Golang was installed successfully. In the terminal, enter the following command to verify:

go version

If you see output similar to the following:

go version go1.17 linux/amd64

The above is the detailed content of How to install golang on linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete