Support >
  About cybersecurity >
  Learn how to set up a Go development environment and write programs using GoLand step by step.
Learn how to set up a Go development environment and write programs using GoLand step by step.
Time : 2025-12-25 14:56:56
Edit : Jtti

Before starting to learn Go, you first need to set up a suitable development environment. Setting up a Go environment is relatively simple, but there are a few key steps that require special attention. We'll start with installing Go itself. Developed by Google, Go is a compiled, statically typed language that balances development efficiency and runtime performance, making it particularly suitable for building modern web services and distributed systems. The official website provides a complete installation package that supports the three major operating systems: Windows, macOS, and Linux.

Visit the official Go website, golang.org, find the download page, and select the installation package corresponding to your operating system. If you are using Windows, it is recommended to download the .msi installation file, which will automatically handle most of the configuration. Double-click the installation file and follow the prompts step by step, remembering to pay attention to the installation path. By default, Go will be installed in the C:\Go directory, but you can choose another location. After installation, you need to verify its success. Open your command-line tool and type `go version`. If Go version information is displayed, such as `go version go1.20.4 windows/amd64`, then the installation was successful.

For macOS users, you can install Go via Homebrew by simply running `brew install go` in the terminal. Linux users can use a package manager, such as Ubuntu:

`sudo apt install golang-go`

However, the version provided by the package manager may not be the latest; it's recommended to download the latest version from the official website.

After installing Go, you need to configure several environment variables. `GOPATH` is an important concept, determining your workspace location. Earlier versions of Go required code to be placed in the directory specified by `GOPATH`. Since the introduction of Go modules, this restriction has been relaxed, but `GOPATH` is still used to store downloaded dependencies and build cache. You can check the current settings using the command `go env GOPATH`.

Next, configure Go modules. This is how modern Go projects manage dependencies, allowing you to place code anywhere, not just in the `GOPATH/src` directory. Enabling module support requires setting the environment variable `GO111MODULE`. In Go 1.16 and later versions, module support is enabled by default, so usually no special settings are needed. However, if you encounter dependency issues, you can explicitly set it to "on" by executing the following command in the command line:

`go env -w GO111MODULE=on`

Initializing a new module is simple: run `go mod init module_name` in your project directory. The module name is usually the repository address, such as `github.com/your_username/project_name`. This command will create a `go.mod` file, recording the project's module information and dependencies.

Due to network issues, downloading dependencies from the official repository can be slow, so configuring a reliable proxy server is essential. Commonly used proxies include goproxy.io and goproxy.cn, which provide fast mirror services. Proxy settings are implemented through the environment variable `GOPROXY`. You can set multiple proxies, separated by commas. For persistent configuration, it is recommended to use the `go env -w` command, for example:

`go env -w GOPROXY=goproxy.cn,direct`

This will cause Go to prioritize downloading from domestic proxies, and if the proxy fails, it will fall back to direct connection. After setting it up, you can verify its effectiveness using `go env GOPROXY`. Now that the basic Go environment is ready, the next step is to install the development tool GoLand. It offers a range of powerful features, including intelligent code completion, code navigation, refactoring tools, and a debugger, significantly improving development efficiency. Visit the JetBrains website, find the GoLand download page, and select the version suitable for your operating system. The download and installation process is similar to other software; simply follow the wizard steps. After installation, the first time you launch it, you'll be prompted to choose a theme and keyboard mapping; choose according to your preferences.

After launching GoLand, you need to configure the Go toolchain so that GoLand knows the Go installation location. Normally, GoLand will automatically detect the installed Go version. If it doesn't recognize it correctly, you can set it manually. Open GoLand's settings: on Windows and Linux, it's under the File menu in Settings; on macOS, it's under the GoLand menu in Preferences. Find the GOROOT option under the Go menu, click the plus sign to add the local Go installation path, and then click Apply to apply the settings. Next, configure GOPATH. On the same settings page, find GOPATH under the Go menu and check that the project GOPATH and global GOPATH are correct. The default values ​​are usually sufficient. If you have a custom GOPATH path, you can add it here.

GoLand also requires configuring a Go module proxy, which will speed up dependency downloads. In settings, find Go Modules under the Go menu and set the Environment field to `GOPROXY=goproxy.cn,direct`, consistent with the previous command-line settings. This will allow GoLand to use this proxy setting when running the `go` command in the background. Additionally, it's recommended to enable "Index the entire GOPATH" for more accurate code completion and navigation, although the initial indexing may take some time depending on your project size and number of dependencies.

Create a new project to test if the environment is working correctly. Click the New Project button in GoLand and select the project location. Select Go as the project type; if using Go modules, ensure this option is checked. Then set the module path, which is the module name mentioned earlier. Click the Create button; GoLand will generate the project structure and initialize the `go.mod` file. Now you can create your first Go file. In the project explorer, right-click the project directory, select New, select Go File, and enter a filename, such as `main.go`. GoLand will automatically create a .go file and add a basic `package main` declaration.

To test the environment, enter the following code in your editor:

`package main`

`import "fmt"`

`func main() {`

`fmt.Println("Hello, GoLand!")

`}`

This code imports the `fmt` package for formatting input and output. It prints a message in the `main` function. To run this code, right-click in the editor and select Run go build main.go, or use the shortcut Ctrl+Shift+F10 (on Windows/Linux) or Control+Shift+R (on macOS). GoLand will compile and run the program, and the result will be displayed in the Run tool window at the bottom. You should see the output Hello, GoLand!. If everything goes smoothly, the environment is configured successfully.

Debugging is another powerful tool in GoLand. You can set breakpoints, execute code line by line, and view variable values. Set a breakpoint by clicking next to the line number, then right-click and select Debug go build main.go. The program will pause at breakpoints, allowing you to step through the code using the single-step execution button in the debug toolbar and observe the changes at each step. This is extremely useful for troubleshooting complex issues. The debugger also supports conditional breakpoints, expression evaluation, and call stack viewing.

As projects grow, managing dependencies becomes crucial. GoLand provides a visual way to view and update dependencies. Right-clicking on the go.mod file, selecting Go Modules, and then choosing Show Dependencies will open a dependency graph displaying all direct and indirect dependencies. You can check for outdated dependencies and quickly update them via the menu. GoLand also supports database tools, version control integration, and Docker container configuration, features particularly useful when developing web services.

Once your development environment is set up, you can delve deeper into the features of the Go language. From basic syntax to concurrent programming, from the standard library to third-party frameworks, the Go ecosystem offers a wealth of resources. Continuous learning and practice are key to mastering any programming language. Using the tools provided by GoLand, you can write, test, and debug code more efficiently. With experience, you'll gradually become familiar with optimizing development processes and building more robust applications. The development environment is just the beginning; its true value lies in using it to create software that solves real-world problems. Now that you're ready, you can begin your Go programming journey.

Pre-sales consultation
JTTI-Defl
JTTI-Coco
JTTI-Amano
JTTI-Eom
JTTI-Jean
JTTI-Ellis
JTTI-Selina
Technical Support
JTTI-Noc
Title
Email Address
Type
Sales Issues
Sales Issues
System Problems
After-sales problems
Complaints and Suggestions
Marketing Cooperation
Information
Code
Submit