Coming from C#/TypeScript to Go, I’ve learned one thing: Go’s simplicity is its superpower. Let’s walk through a clean, official-compliant setup for Linux and VS Code—no comparisons, just practical steps.
Step 1: Installing Go (Official Linux Method)
Per the Go docs:
- Download the tarball:
# Replace the version with the latest from https://go.dev/dl/
wget https://go.dev/dl/go1.22.1.linux-amd64.tar.gz
-
Extract to
/usr/local
:
sudo rm -rf /usr/local/go # Remove old installs first
sudo tar -C /usr/local -xzf go1.22.1.linux-amd64.tar.gz
-
Add Go to your
PATH
:
# Add this line to ~/.bashrc or ~/.zshrc
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrc
- Verify:
go version
# Should output: go1.22.1 linux/amd64
Step 2: Configuring Your Workspace
Go’s official guide recommends modules for dependency management.
- Create a project directory:
mkdir ~/go-projects/hello-world && cd ~/go-projects/hello-world
- Initialize a module:
go mod init example.com/hello-world # Replace with your module path
Step 3: VS Code Setup (Without the Headaches)
- Install the Go extension.
-
Open your project in VS Code and create
main.go
:
package main
import "fmt"
func main() {
fmt.Println("Go + Linux + VS Code: A minimalist’s dream.")
}
-
Install tools:
- When prompted by VS Code, click “Install All” to set up
gopls
,dlv
, etc. - If tools fail (common on Linux), run this in your terminal:
go install golang.org/x/tools/gopls@latest go install github.com/go-delve/delve/cmd/dlv@latest
- When prompted by VS Code, click “Install All” to set up
Step 4: Build & Run
- Build a binary:
go build
# Outputs an executable named after your module (hello-world)
- Run:
./hello-world
- Or run directly:
go run .
Troubleshooting Tips (Linux Edition)
- Permission denied for tools?
sudo chown -R $USER $HOME/go # Reclaim ownership of the Go directory
-
VS Code not recognizing Go?
- Restart VS Code after installing the extension.
- Ensure
gopls
is installed manually if the prompt fails.
Why This Works
- No bloat: Go’s static binaries mean no runtime dependencies—ideal for Linux.
-
Official-first approach: Following Go’s docs avoids legacy
GOPATH
pitfalls. - VS Code integration: The Go extension handles formatting, linting, and debugging out of the box.