Home  >  Article  >  Backend Development  >  How to install golang on linux system

How to install golang on linux system

PHPz
PHPzOriginal
2023-03-22 13:49:131650browse

Golang is an efficient, powerful, and free open source programming language that is currently widely used in the field of large-scale distributed systems and network programming. If you are preparing to use Golang and take full advantage of it, the first thing to do is to install it on your Linux operating system.

This article will show you how to install Golang on Linux for your reference.

Step one: Download Golang

Download the one that suits you on the official website (https://golang.org/dl/) System version 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 command path to facilitate 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

This proves that Golang has been successfully installed!

Conclusion:

The process of installing Golang is not difficult. You only need to follow the above steps to complete it smoothly. Through the above four steps, you can quickly install Golang on the Linux operating system and use it to program on the Linux system.

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:
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