Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring Go Development Environment in Sublime Text 3

Tech 1

Installing Git

Since Go utilizes Git for managing external packages, the initial step involves installing Git. Visit http://www.git-scm.com/download/ to download the appropriate version for your operating system. The installation process is straightforward—simply proceed through the installer. Ensure that "Git Bash here" and "Git GUI here" are selected under Windows Explorer integration.

Installing Go

  1. Navigate to https://golang.org/dl/ to select a suitable package for your platform (for users behind a firewall, use http://golangtc.com/download).

  2. Download the file go1.4.2.windows-amd64.msi and install it to a designated directory, such as E:\Go.

  3. After installation, verify the setup by running go env in the command prompt:

$ go env
set GOARCH=amd64
set GOBIN=E:\GoWorkSpace\bin
set GOCACHE=C:\Users\Administrator\AppData\Local\go-build
set GOENV=C:\Users\Administrator\AppData\Roaming\go\env
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=E:\GoWorkSpace\
set GOROOT=E:\Editor\Go

Confirm that the go command functions correctly. If not, review environment variable configurations.

Setting Up Go Environment Variables

Access the system properties through "My Computer" -> "Advanced Settings" -> "Enviroment Variables".

  1. Check if the GOROOT variable exists and ensure Path includes %GOROOT%\bin.

    If missing, create a new GOROOT variable pointing to your Go root directory (e.g., E:\Editor\Go). Then update Path to append ;%GOROOT%\bin.

  2. Configure GOPATH, which defines your project workspace. This is distinct from the Go installation path. Multiple directories can be specified using semicolons on Windows or colons on Linux. The first directory will be used by default when executing go get. Create a new variable named GOPATH set to E:\GoWorkSpace.

  3. GOBIN defaults to the bin subdirectory within GOPATH. For example: E:\GoWorkSpace\bin

Installing Sublime Text

  1. Download Sublime Text from http://www.sublimetext.com/

  2. Install Package Control by opening the console via View -> Show Console and pasting the following script:

import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())

Press Enter and restart Sublime Text once complete.

To manually install the GoSublime plugin:

  1. Open Preferences -> Browse Packages to locate the packages directory, e.g., C:\Users\...\AppData\Roaming\Sublime Text 3\Packages

  2. If Git is available, navigate into the folder and execute:

git clone https://github.com/DisposaBoy/GoSublime.git

Alternatively, download the zip archive from https://github.com/DisposaBoy/GoSublime and extract it into the packages directory. Rename the extracted folder to GoSublime.

  1. Restart Sublime Text to finalize installation.

Configuring Auto-Execution with Ctrl+B

To enable automatic execution of Go programs using Ctrl+B:

  1. In Preferences -> Browse Packages, locate the GoSublime/src directory. Create a new margo subfolder.

  2. Copy GoSublime/src/margo.sh/extension-example/extension/extension-example.go into the newly created margo folder and rename it to margo.go.

  3. Define a custom build system by going to Tools -> Build System -> New Build System. Replace the default content with:

{
    "encoding":"utf-8",
    "cmd": ["E:/Editor/Go/bin/go","run","$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)"
}

Save this configuration as GoBuild.sublime-build. Select it via Tools -> Build System -> GoBuild to activate.

Upon successful configuration, pressing Ctrl+B should compile and execute the current Go file.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

SBUS Signal Analysis and Communication Implementation Using STM32 with Fus Remote Controller

Overview In a recent project, I utilized the SBUS protocol with the Fus remote controller to control a vehicle's basic operations, including movement, lights, and mode switching. This article is aimed...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.