linux go with vscode
1 install go
1 | apt install golang |
将会同时安装下列软件:
golang-1.9 golang-1.9-doc golang-1.9-go golang-1.9-src golang-doc golang-go
golang-src
建议安装:
bzr
下列【新】软件包将被安装:
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
1 2 | export GOROOT= /usr/share/go-1 .9 export GOPATH=$HOME /go |
使环境变量生效
1 | source $HOME / .profile |
全局的 可以编辑添加到 /etc/profile
source ~/.bash_profile
You can do this by adding this 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 is in your "GOPATH/bin" or "PATH"."
should
1 | go get github.com /derekparker/delve/cmd/dlv |
开始调试 from:https://zhuanlan.zhihu.com/p/26473355
选中要调试的main.go, 点击F5, 既可以开始调试
调试快捷键和Visual Studio系一致
- F9 切换断点
- F10 Step over
- F11 Step in
- Shift+F11 Step out
注意点
- 某些结构体成员无法直接显示时, 可以直接选中变量名, 添加到监视, 或者右键点击: "调试:求值"
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 are 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 (386
) and 64-bit (amd64
) x86 processor architectures.
If a binary distribution is not available for your combination of operating system and architecture, try installing from source or installing gccgo instead of gc.
System requirements
Go binary distributions are available for these supported operating systems and architectures. Please ensure your system meets these requirements before proceeding. If your OS or architecture is not on the list, you may be able to install from source or use gccgo instead.
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 |
CentOS/RHEL 5.x not supported. Install from source for other libc. |
macOS 10.8 or later | amd64 | use the clang or gcc† that 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 use
cgo.
‡You only need to install the command line tools for
Xcode. If you have already
installed Xcode 4.3+, you can install it from the Components tab of the
Downloads preferences panel.
Install the Go tools
If you are upgrading from an older version of Go you must first remove the existing version.
Linux, Mac OS X, and FreeBSD tarballs
Download the archive
and extract it into /usr/local
, creating a Go tree in
/usr/local/go
. For example:
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
Choose the archive file appropriate for your installation. For instance, if you are 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 /usr/local/go/bin
to the PATH
environment variable. You can do this by adding this 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 will be installed in /usr/local/go
(or c:\Go
under Windows), but it is possible to install the Go tools to a different location. In this case you must set the GOROOT
environment variable to point to the directory in which it was 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.X export PATH=$PATH:$GOROOT/bin
Note: GOROOT
must be set only when 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 may need to restart any open Terminal sessions for the change to take effect.
Windows
The Go project provides two installation options for Windows users (besides installing from source): a zip archive that requires you to set some environment variables and an 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 may 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 other than c:\Go
, you must set the GOROOT
environment variable to your chosen path.
Add the bin
subdirectory of your Go root (for example, c:\Go\bin
) to your PATH
environment variable.
Setting environment variables under Windows
Under Windows, you may 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" control panel.
Test your installation
Check that Go is installed correctly by setting up a workspace and building a simple program, as follows.
Create your workspace directory, $HOME/go
. (If you'd like to use a different directory, you will need to set the GOPATH
environment variable.)
Next, make the directory src/hello
inside your workspace, and in that directory create a file named hello.go
that looks like:
package main import "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 will build an executable named hello
in the directory alongside your source code. Execute it to see the greeting:
$ ./hello hello, world
If you see the "hello, world" message then your Go installation is working.
You can run go
install
to install the binary into your workspace's bin
directory or go
clean
to remove it.
Before rushing off to write Go code please read the How to Write Go Code document, which describes some essential concepts about using the Go tools.
Uninstalling Go
To remove an 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 section 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.
--------------------------------------------------
source ~/.bash_profile
SettingGOPATH
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!