Linux

Installing and Configuring Go on Linux: A Step-by-Step Guide

In this guide, you'll learn how to install and set up a Go development environment on Linux from scratch. We'll cover installation from repositories and the official website, configuring PATH and GOPATH, and verifying functionality.

Updated at February 14, 2026
10-15 min
Easy
FixPedia Team
Применимо к:Ubuntu 20.04+Debian 11+Fedora 35+Arch LinuxGo 1.21+

Introduction / Why This Is Needed

Go (Golang) is a modern compiled language created by Google for efficient development of network services and utilities. Setting up a development environment on Linux is an essential first step for working with Go. After completing this guide, you will have a fully functional environment: the compiler installed, paths configured, and you will be able to create, build, and run Go projects.

You will get:

  • Installed go compiler in the terminal
  • Configured environment variables GOROOT, GOPATH, PATH
  • Ability to use go get, go build, go run
  • A ready project structure (if you configure GOPATH)

Requirements / Preparation

Before starting, ensure that:

  1. You have access to a Linux terminal (Ubuntu, Debian, Fedora, Arch, or another distribution).
  2. Basic utilities are installed: curl or wget, tar.
  3. You have sudo privileges (if planning installation in system directories).
  4. Determine your system architecture:
    uname -m
    
    • x86_64amd64
    • aarch64arm64

Step 1: Check for Existing Go and System Architecture

First, let's check if Go is already installed and determine the architecture.

# Check for installed Go (if any)
go version

# Determine architecture
uname -m

If the go version command outputs a version (e.g., go version go1.20 linux/amd64), Go is already installed. You can proceed to Step 5 to check environment variables or remove the old version before installing a new one.

Step 2: Choose an Installation Method

There are two main options:

MethodProsConsWhen to choose
Via package manager (apt, dnf, pacman)Simple, automatically in PATH, updates via systemVersion often not the latestFor quick installation if the latest version is not critical
From the official website (golang.org/dl)Latest stable version, control over locationRequires manual PATH configurationFor development when new features or a specific version are needed

Recommendation: If you are starting a new project or want to use Go Modules (the modern standard), choose installation from the official website.

Step 3: Installation via Package Manager

For Ubuntu/Debian:

# Update package cache
sudo apt update

# Install Go
sudo apt install golang

# Check version (should be, e.g., 1.18+ in modern repositories)
go version

For Fedora/RHEL/CentOS:

sudo dnf install golang
go version

For Arch Linux:

sudo pacman -S go
go version

Note: In some distributions, the package is called golang or go. After installation via package manager, environment variables are usually configured automatically. Proceed to Step 5.

Step 4: Installation from Official Website (Manual)

This method gives you the latest version and full control.

  1. Go to the downloads page (can be done via terminal):
    # For amd64
    wget https://go.dev/dl/go1.21.6.linux-amd64.tar.gz
    
    # For arm64
    wget https://go.dev/dl/go1.21.6.linux-arm64.tar.gz
    

    Check the latest version at golang.org/dl.
  2. Remove the old version (if installed in /usr/local/go):
    sudo rm -rf /usr/local/go
    
  3. Extract the archive to /usr/local (requires sudo):
    sudo tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz
    
  4. Ensure Go is added to PATH. Add lines to ~/.bashrc (or ~/.zshrc for zsh):
    # Open the file in an editor
    nano ~/.bashrc
    

    Add at the end:
    export GOROOT=/usr/local/go
    export PATH=$PATH:$GOROOT/bin
    export GOPATH=$HOME/go
    export PATH=$PATH:$GOPATH/bin
    

    💡 Tip: If you don't want to install in a system directory, extract the archive to ~/go or ~/local/go and specify the corresponding GOROOT.

  5. Apply changes:
    source ~/.bashrc
    

Step 5: Configure Environment Variables (if not done earlier)

Even when installing via package manager, it's worth checking/configuring GOPATH.

  1. Check current variables:
    go env
    
  2. Ensure GOPATH is set. If output shows GOPATH="", add to ~/.bashrc:
    export GOPATH=$HOME/go
    export PATH=$PATH:$GOPATH/bin
    
  3. Create a directory for projects (if it doesn't exist):
    mkdir -p $GOPATH/{src,bin,pkg}
    
  4. Reload the shell:
    source ~/.bashrc
    

Step 6: Verify the Setup

Run commands for a full check:

# 1. Check Go version
go version
# Expected output: go version go1.21.6 linux/amd64

# 2. Check environment variables
go env GOROOT GOPATH PATH
# GOROOT should point to /usr/local/go (or your directory)
# GOPATH should point to /home/your_user/go

# 3. Simple test project
mkdir -p $GOPATH/src/hello
cat > $GOPATH/src/hello/main.go << 'EOF'
package main
import "fmt"
func main() {
    fmt.Println("Hello, FixPedia!")
}
EOF

# 4. Run
go run $GOPATH/src/hello/main.go
# Should output: Hello, FixPedia!

# 5. Build binary
go build -o $GOPATH/bin/hello $GOPATH/src/hello/main.go
hello
# Should output: Hello, FixPedia!

If all steps completed successfully — the environment is ready for work.

Common Issues

go: command not found

Cause: Go not added to PATH. Solution:

  1. Check that ~/.bashrc (or ~/.zshrc) contains export PATH=$PATH:/usr/local/go/bin.
  2. Run source ~/.bashrc or log out and back into the terminal.

❌ Permission error when extracting to /usr/local

Cause: Insufficient privileges. Solution: Use sudo for extraction or install Go in your home directory (~/go).

go env shows empty GOPATH

Cause: Variable not set. Solution: Add export GOPATH=$HOME/go to ~/.bashrc and reload the shell.

❌ Outdated version in distribution repository

Cause: Linux repositories often contain stable but not the latest versions. Solution: Install from the official website (see Step 4).

❌ Go version conflict

Cause: Multiple Go versions installed, and go points to an undesired one. Solution: Check which go and ls -l $(which go). Remove extra versions or adjust the order in PATH.


Advanced Configuration (Optional)

Configuring Modules (Go Modules)

Starting with Go 1.11, modules are the standard for dependency management. Ensure they are enabled:

go env -w GO111MODULE=on

Configuring a proxy for modules (if access is needed in Russia/China)

go env -w GOPROXY=https://goproxy.cn,direct

Autocompletion for bash/zsh

Install the plugin for autocompletion of go commands:

# For bash
go install golang.org/x/tools/cmd/godoc@latest
echo "source <(godoc -completion)" >> ~/.bashrc

Final Verification

After setup, perform a full workflow:

  1. Create a new module:
    mkdir ~/projects/myapp && cd ~/projects/myapp
    go mod init github.com/username/myapp
    
  2. Add simple code:
    cat > main.go << 'EOF'
    package main
    import "fmt"
    func main() {
        fmt.Println("Go is ready!")
    }
    EOF
    
  3. Build and run:
    go build -o myapp .
    ./myapp
    

If you see Go is ready!, congratulations, the environment is fully functional!

What's next?

  • Explore the official tutorial
  • Set up an IDE (VS Code with Go extension, Goland)
  • Master Go Modules for dependency management

F.A.Q.

Which version of Go should I choose for installation?
Do I need to use sudo when installing Go?
What is GOPATH and is it necessary to configure it?
How do I update Go to a new version?

Hints

Check for existing Go and system architecture
Choose installation method
Install via package manager (apt/dnf/pacman)
Install from official website (manual)
Configure environment variables
Verify installation
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community