Home > Article > Development Tools > What should I do if the go language vscode cannot be installed?
What should I do if the go language vscode cannot be installed?
Installation and Configuration of Go Language - vscode Chapter
If you want to start the development journey of go language, but have not taken the first step yet, Then this article should get you started quickly and with less detours.
Recommended related tutorials: vscode tutorial
Note: This article is based on the Windows operating system, the editor uses vscode, and the language should be kept as brief as possible.
Before you start, you need to know how to configure the environment variables of the Windows system. It is relatively simple and will not be repeated here.
Installation steps
Go download address: https://golang.google.cn/
vscode download address: https://code. visualstudio.com/Download
Go and vscode installation steps: Select the path and keep [Next] until the end. (Go in this article is installed in c:\Go)
Notes
After the installation is successful, there will be some changes in the environment variables:
Add the bin directory of the Go installation directory to path in order to execute the go command.
GOROOT is newly added to the environment variable, and the default value is the installation directory (mine is c:\Go)
GOPATH is newly added to the environment variable, and my default value is C:\ Users\Administrator\go, you can set this directory manually, and you can set multiple values to store the packages and commands downloaded by go. Subsequent packages you write must also be placed in the directory specified by GOPATH.
Under normal circumstances, the above environment variables will be automatically set after installing go. If they are not automatically set, manual modification is also possible.
After the installation is completed, open the command line and enter go version. If the go version is prompted, the installation is successful.
vscode settings
Open vscode and create a new file with the suffix go. vscode will automatically prompt you to install the Go plug-in. You can see the highlight of Go after installing it directly. shown.
Next we can write our "hello world" program.
package main import "fmt" func main() { fmt.Println("Hello world") }
Filling the pit
When we write the go program in vscode, some prompts will appear, asking us to download some packages, but these packages cannot be downloaded directly due to some well-known reasons. We need to download it manually, and the steps are very simple (again, we need to download and install Git before, and add the git command to the environment variable.).
Open the directory corresponding to GOPATH. Mine is C:\Users\Administrator\go. There will be a src directory (there may also be bin and pkg directories). Create a new directory in src. The structure is as follows Display (if it already exists, there is no need to create a new one, just complete the ones that do not exist):
github.com golang golang.org x
After the directory is successfully created, execute
git clone https://github.com/golang/tools.git tools
in the x directory and then copy the downloaded tools directory Copy to the golang directory. At this point, the directory structure becomes:
github.com golang tools golang.org x tools
At this point, when vscode displays the installation prompt again, we click Install and the installation is successful.
But if the installation still cannot be successful, we can also install it manually and execute the following commands respectively.
go install github.com/ramya-rao-a/go-outline go install github.com/acroca/go-symbols go install golang.org/x/tools/cmd/guru go install golang.org/x/tools/cmd/gorename go install github.com/josharian/impl go install github.com/rogpeppe/godef go install github.com/sqs/goreturns go install github.com/golang/lint/golint go install github.com/cweill/gotests/gotests
vscode code prompt
Now, we have successfully installed the package of vscode prompt, but there is still a small problem, that is, vscode does not have go code prompt, we only need to configure it simply Just vscode, the configuration code is as follows (settings.json):
{ "go.autocompleteUnimportedPackages": true, "go.gocodePackageLookupMode": "go", "go.gotoSymbol.includeImports": true, "go.useCodeSnippetsOnFunctionSuggest": true, "go.inferGopath": true, "go.gopath": "C:/Users/Administrator/go", "go.useCodeSnippetsOnFunctionSuggestWithoutType": true, }
Finally
In this way, we can happily play with Go in vscode~~~~~
The above is the detailed content of What should I do if the go language vscode cannot be installed?. For more information, please follow other related articles on the PHP Chinese website!