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
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.
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".
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.
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.
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/
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.
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.
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.
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!