Home >Backend Development >Golang >How to install Golang language

How to install Golang language

PHPz
PHPzOriginal
2023-04-24 15:48:50524browse

Golang (also known as Go language) is a programming language developed by Google. The original design is to improve the operating efficiency and development efficiency of programs. This article will introduce how to install the Golang language.

  1. Preparation
    Before starting the installation, you must ensure that your operating system has the appropriate version of Golang installed. If it is not installed, you can download the correct version of the binary file from the Golang official website.
  2. Download Golang
    You can find binary file downloads for various platforms on the Golang official website. Here we choose binaries suitable for Linux systems.

Enter the following command in the terminal window to download the Golang binary for Linux systems.

$ wget https://golang.org/dl/go1.15.3.linux-amd64.tar.gz
  1. Install Golang

After the download is complete, we need to decompress and install the Golang file. To unzip the files you can use the following command:

$ tar -C /usr/local -xzf go1.15.3.linux-amd64.tar.gz

This will create a subdirectory named "go" under the /usr/local directory and place all unzipped files here Under contents.

Next, we need to add the path of the Golang binary file to the system environment variable. The path can be added to the environment variable using the following command:

$ echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
$ source ~/.bashrc
  1. Testing Golang

After Golang is installed, we can test to make sure it was installed successfully. Enter the following command in the terminal window:

$ go version

If everything is fine, you should see the following output:

go version go1.15.3 linux/amd64
  1. Start using Golang
    Now you have successfully installed Golang, It's time to start using it. You can use any text editor to write source code. After saving the file, name it main.go and compile it using the following command:
$ go build main.go

This will generate an executable file main in the current directory.

Now, you can use the following command to run the program:

$ ./main

At this point, you have successfully installed Golang and written your first program. Happy programming!

The above is the detailed content of How to install Golang language. 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