Installing go language development environment on centos virtual machine

Posted by Ton Wibier on Wed, 11 Sep 2019 15:57:12 +0200

Article directory

Reference material

This experiment draws on the following references

This paper mainly describes the general experimental process, experimental results, as well as some problems encountered in the experimental process and solutions (the text is the part of the need to pay attention to / trampled pits)

Experimental environment: centos virtual machine installed on Visual Box

Install VScode

Open the terminal and enter the following commands to install it

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
yum check-update
sudo yum install code

Reference resources: Running VS Code on Linux

If'... The mistake of "unreachable network" may be that the network is bad rather than the network card configuration is wrong: (so only a better campus network environment is needed (such as the evening public school building).

There's another one that hasn't come yet and that hasn't been put into practice. Solution

create shortcut

Entering code directly at the terminal can also be opened
If you want to create a shortcut, then the top left corner "location" - computer, path "user" - share"- application, right-click to copy to the desktop. (and then a confirmation of trust)


Successful installation

Install golang

install

The order is as follows

  sudo yum install golang

If you encounter the following error

Then you need to install EPEL first and run the following commands.

yum install -y epel-release

Configuring environment variables

Create gowork workspace and three subfolders

mkdir $HOME/gowork
mkdir $HOME/gowork/bin
mkdir $HOME/gowork/pkg
mkdir $HOME/gowork/src

Then, open the profile file with vim

vim etc/profile

Add statements that modify environment variables to the end of the file

export GOPATH=$HOME/gowork
export PATH=$PATH:$GOPATH/bin

Execution configuration

source etc/profile

Checking the configuration with go env at this point, you can see the environment variables of GOPATH and GOROOT.

Execute go version to confirm that go is installed

Note that since this is done in root mode, $HOME is root/, and GOPATH is root/gowork through export GOPATH=$HOME/gowork configuration

However, if you boot up again, the default of $HOME is home/username, that is, GOPATH is home/username/gowork, which cannot be changed even when you enter root mode, so remember to execute source etc/profile again and confirm the configuration with go env.

Create hello, world

Create a code directory and enter

mkdir -p $GOPATH/src/github.com/github-user/ServiceComputing
cd $GOPATH/src/github.com/github-user/ServiceComputing 

Enter code to open vscode and create hello.go
If it's in root mode, add the parameter -- user-data-dir

package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

implement

go run hello.go


Establishing hello executable file

go install github.com/github-user/ServiceComputing/hello.go

ServiceComputing is then generated in the bin folder, and since the environment variable PATH=$PATH:$GOPATH/bin is set, direct input can be executed.

Install git

install

sudo yum install git

Create git local repository and bind

Install go tools

#create folder
mkdir $GOPATH/src/golang.org/x/
#Download source code
go get -d github.com/golang/tools
#copy 
cp $GOPATH/src/github.com/golang/tools $GOPATH/src/golang.org/x/ -rf
#Setup Toolkit
go install golang.org/x/tools/go/buildutil

Exit vscode and re-enter. Installation will be prompted

Install gotour

go get github.com/Go-zh/tour/gotour

Then run tour ** (not gotour)**

If you run gotour

The first library

First test

See github:

Topics: github yum git network