Home  >  Article  >  Backend Development  >  How to install golang

How to install golang

WBOY
WBOYOriginal
2023-05-19 10:46:37464browse

How to install golang

Go language (also known as golang) is a high-performance, cross-platform programming language. It has powerful concurrency features and excellent memory management capabilities, so it is very popular among developers. their favor. This article will introduce how to install and configure golang for beginners.

Install Golang

  1. Visit the official website

Enter "https://golang.google.cn/dl/" in the browser to open golang On the official website, you can see the list of currently available golang versions.

  1. Select the download version

According to the operating system, select the appropriate version to download. For example, to install 64-bit golang on Windows 10, you should select "go1.15.7.windows-amd64.msi".

  1. Download and Installation

After downloading, double-click to run the .msi installation file obtained after downloading. After the installation wizard appears, follow the prompts to set up and install.

  1. Verify installation

After the installation is completed, verify whether golang has been successfully installed through the following code:

$ go version
go version go1.15.7 windows/amd64

If the correct version number is output, explain Golang has been installed successfully.

Configuring Golang

In order to better use golang, we need to complete the necessary environment configuration.

  1. GOPATH environment variable

Enter the following command in the command line window to set the GOPATH environment variable.

$ export GOPATH=$HOME/go

The path of GOPATH is set here to "/home/d6025a37ea8687b5422f951f7288bdc5/go". Of course, you can set this to any directory you wish.

  1. GOROOT environment variable

GOROOT is the root directory of golang installation. Enter the following command in the command line window and set the GOROOT environment variable in the .bashrc file:

$ export GOROOT=/usr/local/go
$ export PATH=$PATH:$GOROOT/bin

If installed on Windows, sometimes you need to refresh the CMD or PowerShell environment variables to take effect.

Install third-party toolkits

There are many third-party toolkits in Golang that can speed up development and increase productivity. The following introduces how to install some commonly used third-party tool packages.

  1. Installing Git

In many cases, we need to use Git to clone the code repository from Github. You can download the version suitable for your system from the Git official website.

  1. Change HTTP proxy

When we download data from foreign code warehouses, sometimes there will be problems with slow download speed or failure to connect. At this time it is best to set up an HTTP proxy.

$ export http_proxy=http://proxyserverurl:port
$ export https_proxy=http://proxyserverurl:port

Among them, the URL and port of the proxy server need to be set accordingly according to your situation.

  1. Install commonly used third-party packages

There are many excellent third-party packages in Golang. The following introduces how to install some commonly used packages, for example:

$ go get github.com/gin-gonic/gin
$ go get github.com/go-sql-driver/mysql
$ go get gopkg.in/yaml.v2

After successful installation, these packages will be downloaded and installed in the $GOPATH/src directory. (If GOPATH is not customized, it should be in the $HOME/go/src directory)

Summary

Installing and configuring golang is the first step to develop using golang. This article introduces How to install and configure golang, as well as install commonly used third-party packages. After completing these preparations, developers can start using golang and enjoy its efficiency, simplicity, and security features.

The above is the detailed content of How to install golang. 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
Previous article:golang query htmlNext article:golang query html