Ubuntu 16.04 installs the go language and configures the VSCode environment

1. Go language installation

1. Download the installation file
Since the go language is developed by goole, the official website is blocked, we can download it from the domestic mirror website.
https://www.golangtc.com/download
The source code used for this installation is: go1.9.2.linux-amd64.tar.gz
2. Unzip the installation file to the specified directory

$sudo tar -xzvf go1.9.2.linux-amd64.tar.gz -C /usr/local

3. Add environment variables
Edit the /etc/profile file and add the following information at the end

export GOROOT=/usr/local/go
export GOBIN=$HOME/learn/go/bin
export PATH=$PATH:$GOBIN:$GOROOT/bin
export GOPATH=$HOME/learn/go
//使文件生效:
$source /etc/profile

4. Check if the installation is successful

$go version
go version go1.9.2 linux/amd64

A successful display of the version number indicates that the environment variable configuration is successful.

2. VSCODE configuration

1. Install vscode, directly download the deb package from the official website and install it.
2. Change the permissions, because some plugins in vscode need to be installed under the GOBIN environment variable

$sudo chmod 777 $HOME/learn/go/bin

3. Create three new folders in the learn/go directory, bin, pkg, src
4. Vscode installation extension tool
gocode
godef
golint
go-find-references
go-outline
go-symbols
guru
gorename
goreturns
gopkgs a
total of 10, try to install automatically , four were successful.
Manual installation, the directory is located under $HOME/learn/go/bin
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
go get -u -v github.com /golang/lint/golint
go get -u -v github.com/lukehoban/go-find-references
go get -u -v github.com/lukehoban/go-outline
go get -u -v sourcegraph.com/sqs/ goreturns
go get -u -v golang.org/x/tools/cmd/gorename
go get -u -v github.com/tpng/gopkgs
go get -u -v github.com/newhook/go-symbols
go get -v -u github.com/peterh/liner
github.com/derekparker/delve/cmd/dlv And the problem of the wall, so the ultimate solution is directly used:
when you use VScode to automatically install the plug-in, you also download the plug-in from git, so we can download and install it directly from git.
Git download website: https://github.com/golang/tools , there are download and installation methods on it.
If all is well, only gorename and guru are walled.
Various installation methods, just download and install.
5. User
Settings Preferences -> User Settings

{
    "files.autoSave": "onFocusChange",  
    "go.buildOnSave": "package",  
    "go.lintOnSave": "package",  
    "go.vetOnSave": "package",  
    "go.buildFlags": [],  
    "go.lintFlags": [],  
    "go.vetFlags": [],  
    "go.formatTool": "goreturns",  
    "go.goroot": "/usr/local/go",  
    "go.gopath": "/home/carl/learn/go",  
    "workbench.colorTheme": "Monokai"
}

3. Go language running command

Go run directly runs
Go build to compile, compile it into an executable file, install it in the current path with
Go install, and install it to $GOPATH/bin

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325854498&siteId=291194637