Linux go with Vscode

Source: Internet
Author: User
Tags directory create install go

1 Install Go

Apt Install Golang

The following software will be installed at the same time:
golang-1.9 golang-1.9-doc golang-1.9-go golang-1.9-src golang-doc golang-go
Golang-src
Recommended Installation:
Bzr
The following "new" packages will be installed:
Golang golang-1.9 golang-1.9-doc golang-1.9-go golang-1.9-src Golang-doc
Golang-go GOLANG-SRC
2 Set env

Vim $HOME/.profile and add

Export Goroot=/usr/share/go-1.9export gopath= $HOME/go

You can do this by adding the line to your /etc/profile (for a system-wide installation) or $HOME/.profile :

Export path= $PATH:/usr/local/go/bin

3 Install Vscode

Https://code.visualstudio.com/docs/?dv=linux64_deb

Https://vscode.cdn.azure.cn/stable/0759f77bb8d86658bc935a10a64f6182c5a1eeba/code_1.19.1-1513676564_amd64.deb

Dpkg-i Code_1.19.1-1513676564_amd64.deb

Install go go for Visual Studio Code

4 Debug with Vscode

If error:failed to continue: "Cannot find Delve debugger. Install from Https://github.com/derekparker/delve & ensure it was in your "Gopath/bin" or "PATH". "

Should

Go get GITHUB.COM/DEREKPARKER/DELVE/CMD/DLV

Start Debugging from:https://zhuanlan.zhihu.com/p/26473355

Select the main.go you want to debug, and click F5 to start Debugging

Debugging shortcut keys is consistent with Visual Studio system

    • F9 Toggle Breakpoint
    • F10 Step Over
    • F11 Step in
    • Shift+f11 Step out

Watch out.

    • When some struct members cannot be displayed directly, the variable name can be directly selected, added to the watch, or right-clicked: "Debug: Evaluate"

5 Goland is good:

-------------------------------------------------------------------------

Https://golang.org/doc/install

Download the Go distribution

Download Go Click here to visit the Downloads page

Official binary distributions is available for the FreeBSD (release 8-stable and above), Linux, Mac OS X (10.8 and above) , and Windows operating systems and the 32-bit () and 386 64-bit ( amd64 ) X86 processor architectures.

If A binary distribution is not available for your combination of operating system and architecture, try installing from S Ource or installing GCCGO instead of GC.

System Requirements

Go binary distributions is available for these supported operating systems and architectures. Please ensure your system meets these requirements before proceeding. If your OS or architecture is isn't on the list, you may be able to install from source or use GCCGO instead.


Td>centos/rhel 5.x not supported. Install from source to other libc.
operating system architectures notes
FreeBSD 9.3 or later AMD64, 386 Debian GNU/KFREEBSD not supported
Linux 2.6.23 or later with glibc AMD64, 386, arm, arm64,
s390x, Ppc64le
MacOS 10.8 or later AMD64 Use the clang or gcc? This comes with Xcode? for cgo support
Windows XP SP2 or later AMD64, 386 use MinGW gcc? . No need for Cygwin or msys.

? A C compiler is required only if you plan to USECGO.
? You have need to install the command line tools Forxcode. If you have alreadyinstalled Xcode 4.3+, you can install it from the Components tab of the Thedownloads Preferences panel.

Install the Go Tools

If you is upgrading from a older version of Go you mustfirst remove the existing version.

Linux, Mac OS X, and FreeBSD tarballs

Download the Archiveand extract it into /usr/local , creating a Go tree in /usr/local/go . For example:

Go$version. $OS-$ARCH. tar.gz

Choose the archive file appropriate for your installation. For instance, if you were installing Go version 1.2.1 for 64-bit x86 on Linux, the archive you want is called go1.2.1.linux-amd64.tar.gz .

(typically these commands must be run as root or through sudo .)

Add to the /usr/local/go/bin PATH environment variable. You can do this by adding the line to your /etc/profile (for a system-wide installation) or $HOME/.profile :

Export path= $PATH:/usr/local/go/bin
Installing to a custom location

The Go binary distributions assume they'll be a installed /usr/local/go in (or c:\Go under Windows), but it's possible to install The Go tools to a different location. In this case you must set the GOROOT environment variable-to-the-directory in which it is installed.

For example, if you installed Go to your home directory you should add commands like the following to $HOME/.profile :

Export goroot= $HOME/go1. Xexport path= $PATH: $GOROOT/bin

Note: GOROOT must is set only if installing to a custom location.

Mac OS X Package Installer

Download The package file, open it, and follow the prompts to install the Go tools. The package installs the Go distribution to /usr/local/go .

The package should put the /usr/local/go/bin directory in your PATH environment variable. You could need to restart any open Terminal sessions for the change to take effect.

Windows

The Go project provides the installation options for Windows users (besides installing from source): A zip archive that re Quires you to set some environment variables and a MSI installer that configures your installation automatically.

MSI Installer

Open the MSI file and follow the prompts to install the Go tools. By default, the installer puts the Go distribution in c:\Go .

The installer should put the c:\Go\bin directory in your PATH environment variable. You could need to restart any open command prompts for the change to take effect.

ZIP Archive

Download the zip file and extract it into the directory of your choice (we suggest c:\Go ).

If you chose a directory of other than c:\Go , you must set the GOROOT environment variable to your chosen path.

ADD bin The subdirectory of your Go root (for example, c:\Go\bin ) to your PATH environment variable.

Setting Environment variables under Windows

Under Windows, you could set environment variables through the "Environment variables" button on the "Advanced" tab of the " System Control Panel. Some versions of Windows provide this control panel through the "Advanced system Settings" option inside the "SYSTEM" cont Rol panel.

Test Your Installation

Check that Go was installed correctly by setting up a workspace and building a simple program, as follows.

Create Your workspace directory, $HOME/go . (If you're a different directory, you'll need to set the GOPATH environment variable.)

Next, make the directory src/hello inside your workspace, and in this directory create a file named that hello.go looks like:

Package Mainimport "FMT" Func Main () {    fmt. Printf ("Hello, world\n")}

Then build it with the go tool:

CD $HOME/go/src/hello Go Build

The command above would build an executable named in the hello directory alongside your source code. Execute it to see the greeting:

./helloHello, world

If you see the ' Hello, world ' message then your Go installation is working.

You can run to go install install the binary into your workspace's bin directory or to go clean remove it.

Before rushing off to write go code for read the How to write go Code document, which describes some essential concepts about using the Go tools.

Uninstalling Go

To remove a existing Go installation from your system delete the go directory. This is usually /usr/local/go under Linux, Mac OS X, and FreeBSD or c:\Go under Windows.

You should also remove the Go bin directory from your PATH environment variable. Under Linux and FreeBSD you should edit /etc/profile or $HOME/.profile . If you installed Go with the Mac OS X package then you should remove the /etc/paths.d/go file. Windows users should read the sections about setting environment variables under Windows.

Getting Help

For help, see the list of Go mailing lists, forums, and places to chat.

Report bugs either by running " go bug ", or manually at the Go issue tracker.

Linux go with Vscode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.