当前位置:网站首页>Extended learning - download, installation and environment configuration of golang

Extended learning - download, installation and environment configuration of golang

2020-12-07 14:41:21 The simplicity of developing small programs

For reasons well known at home , We can't have direct access to golang Official website , So download go Language installation package also needs to find another way . Now let's use domestic golang Source to download the installation package as an example , This paper golang The download 、 How to install and configure .

go Language Download

golang The address of our website is https://golang.org/dl/ . Just know , It's unrealistic to expect to open it and download it from it .
Domestic download address :https://studygolang.com/dl . Choose the appropriate installation package for your system . As shown in the figure :
![ Choose the right one golang Version installation package ]install-dl.png

go Language installation and environment configuration

When the download is complete , In your download directory , Find the... You downloaded golang Installation package .

windows Next golang Installation

Double click to run the downloaded installation package and click next (Next)
 Double click to run the installation package
 Start installation
There will be license, Choose to accept (I accept the terms in the License Agreeement.), Click next (Next)
 Accept license
Click next (Next), Choose the installation path . This step defaults to . Remember the installation path here , You can choose to copy this path , When setting environment variables later .
 Set the installation path
Click next (next), Come to the start installation interface , Click on the install (Install) Start installation .
 Click on the install
This step can wait until it is installed , No need to operate .
 setup script
The installation is complete , Click finish (finish) End the installation process .
 End installation

windows Next golang Environment configuration

Right click on my computer , open “ attribute ” menu
 Environment variable Settings
choice “ Advanced system setup ”
 Select advanced system settings
In the pop-up to the end of the flower , choice “ senior ” label , Click the environment variable button , In the pop-up variable setting window , Click the new button under the system variable , add to GOROOT Variable , The variable value is the path installed above :C:\Go\.
 Double click to run the installation package
Modify system variables Path, Additional C:\Go\bin . Be careful here , If you change the installation directory above , Be sure to follow the installation directory , Don't copy blindly , Otherwise, the configuration may not take effect .
 Double click to run the installation package
After setting the environment variable , Enter... In the command go. If you see the screenshot below , It shows that a configuration is successful .
 Double click to run the installation package
 Double click to run the installation package

congratulations , Here we are , You can start with peace of mind golang Take a trip .

linux Lower installation and configuration golang Method

linux There are multiple distributions , They have different installation methods , It is recommended to use the package management commands of various versions to install .

Ubuntu Lower installation and configuration golang Method

Direct installation

First install the latest golang Source , Otherwise, it is installed in the old version

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update

Start installation golang

sudo apt-get install golang-go

Compilation and installation

Unzip it and download it linux Installation package

sudo tar -zxvf go1.15.5.linux-amd64.tar.gz -C /usr/local/

go1.15.5.linux-amd64.tar.gz Is the name of the compressed package you downloaded , According to your modification , Don't use my instructions directly ,/usr/local Is designated golang Installation path , You can modify and choose another path .

Environment variable configuration

GOPATH The path configured in the variable is our development Directory , amount to workspace, Special storage project , You can create a new one under the current user go Folder as development Directory , , Then the path of the directory is :$HOME/go, $HOME It's your /home/ user name /go.
use go mod To order the management of the project , Items can be placed in GOPATH Under the table of contents .

sudo vim ~/.bashrc

In the open file , Add these three lines of code to the last side of the file

export GOPATH=$HOME/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:${GOPATH//://bin:}/bin

The first line is my own configuration golang Working directory of , It varies from person to person , The following two lines are the same . Save and close after input , Then type the command : source ~/.bashrc Enable environment variables . We can type in the command go env To see our configured environment variables :
linux environment variable
Generate our development environment Directory :

cd $GOPATH #, That's the folder above 
mkdir bin
mkdir src
mkdir pkg

thus Ubuntu Next golang The installation of is over .

centos Lower installation and configuration golang Method

Centos Lower installation golang and Ubuntu Lower installation golang Be the same in essentials while differing in minor points , It's just that the package management commands are inconsistent .

Direct installation

First install the latest golang Source , Otherwise, it is installed in the old version

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update

Start installation golang

sudo yum -y install golang

Other installation steps

Other installation steps and environment variable configuration , and Ubuntu The following installation configuration is the same , Please look up .

mac Lower installation and configuration golang

mac Software packages are usually very new , Just use the command directly .

brew install golang

Download the installation package to install : Double click directly to run go1.15.5.darwin-amd64.pkg.

Environment variable Settings

vim ~/.bashrc
#  If it's installed zsh, Please open the file below 
vim ~/.zshrc

Add code at the end of the open interface :

export GOPATH="/Users/aaa/go"

Be careful : The path here aaa Indicates your user name , Please change to the correct path according to your user name .

end

The installation should have ended at this point . however , For well-known reasons , We also need some special configuration :
linux、mac User opens ~/.bashrc

vim ~/.bashrc
#  If mac The user installed zsh, Please open the file below 
vim ~/.zshrc

Enter... In the open file :

GOPROXY=https://goproxy.cn

Add a Chinese agent . And then execute source ~/.bashrc Make it work .

Deo gratias . Start the download golang Develop tools . It is recommended to select and use GoLand

版权声明
本文为[The simplicity of developing small programs]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201207143827809c.html