Go Development Environment
Before starting to learn Go, we need to set up a complete development environment. This chapter will detail how to install and configure the Go development environment on different operating systems.
🛠️ System Requirements
Supported Operating Systems
- Windows: Windows 10 or higher
- macOS: macOS 10.15 or higher
- Linux: Major distributions (Ubuntu, CentOS, Debian, etc.)
- FreeBSD: FreeBSD 12 or higher
Hardware Requirements
- CPU: x86-64 or ARM64 architecture
- Memory: Minimum 2GB RAM, 4GB or more recommended
- Disk Space: At least 500MB available space
📥 Installing Go
Method One: Official Installation Package (Recommended)
Windows
-
Download Installation Package
- Visit Go Official Website
- Download the appropriate Windows installer (.msi file)
- Example:
go1.21.0.windows-amd64.msi
-
Run Installer
-
Verify Installation
macOS
-
Download Installation Package
-
Install Using Homebrew (Recommended)
-
Verify Installation
Linux
-
Download and Extract
-
Configure Environment Variables
-
Verify Installation
Method Two: Package Manager Installation
Ubuntu/Debian
CentOS/RHEL/Fedora
Arch Linux
⚙️ Environment Variable Configuration
Important Environment Variables
Windows Configuration
-
Open System Environment Variables
-
Add Environment Variables
-
Verify Configuration
macOS/Linux Configuration
-
Edit Configuration File
-
Add Environment Variables
-
Apply Configuration
-
Verify Configuration
🏗️ Workspace Structure
Traditional GOPATH Mode
Modern Module Mode (Go 1.11+)
🛠️ Development Tool Selection
1. Visual Studio Code (Recommended)
Install VS Code
Install Go Extension
- Open VS Code
- Press
Ctrl+Shift+Xto open extensions marketplace - Search and install "Go" extension (Google official)
- Restart VS Code
Configure Go Tools
VS Code Configuration File
2. GoLand (JetBrains)
Features
- Powerful IDE
- Intelligent code completion
- Debugging and testing tools
- Version control integration
Installation
3. Vim/Neovim
vim-go Plugin
4. Other Editors
- Sublime Text: GoSublime plugin
- Atom: go-plus plugin
- Emacs: go-mode
🔧 Go Toolchain
Basic Commands
Useful Third-Party Tools
Code Formatting
Code Linting
Dependency Management
🚀 Creating Your First Go Program
1. Create Project Directory
2. Initialize Module
3. Create Main Program
4. Run Program
5. Project Structure
🌐 Configure Network Proxy (Chinese Users)
Go Module Proxy
Verify Proxy Configuration
🔍 Common Issues Troubleshooting
1. Environment Variable Issues
2. Permission Issues (Linux/macOS)
3. Network Issues
4. Version Conflicts
📋 Environment Check List
Before continuing with subsequent learning, ensure the following are properly configured:
- Go successfully installed (
go versionshows version info) - Environment variables correctly configured (
go envshows correct paths) - Development tools installed with Go extension configured
- Network proxy configured (Chinese users)
- First Go program created and run
- Go toolchain commands working normally
🎓 Summary
In this chapter, we completed the full setup of the Go development environment:
- ✅ Install Go: Through official installer or package manager
- ✅ Configure Environment: Set necessary environment variables
- ✅ Choose Tools: Install and configure development tools
- ✅ Workspace: Understand Go's project structure
- ✅ First Program: Create and run Hello World
- ✅ Network Optimization: Configure proxy to speed up downloads
A good development environment is the foundation for efficient learning and development. Now you have a complete Go development environment and can start learning Go's core concepts.
Next, let's learn about Go Command Line Tools to master the basic Go toolchain usage.
It's recommended to document the development environment configuration steps so they can be quickly reproduced when setting up on other machines. Also, regularly update Go version to get the latest features and performance improvements.