How to Install Go on Linux and Configure Environment Variables in Minutes

This guide walks you through downloading the Go binary, extracting it to /usr/local, verifying the installation, and setting up essential environment variables like GOROOT and GOPATH so you can run Go commands directly from the terminal.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Install Go on Linux and Configure Environment Variables in Minutes

Install Go

Go installation is very simple compared to other language environments: just download the archive and extract it.

1. Download the archive (official site https://golang.org/dl/ is blocked in China, use the Chinese mirror https://studygolang.com/dl). Example:

wget https://studygolang.com/dl/golang/go1.17.1.linux-amd64.tar.gz

# If wget is not installed:
# yum install wget  OR  download via browser and upload via FTP

2. Extract to the application directory

$ tar -zxvf go1.17.1.linux-amd64.tar.gz -C /usr/local/

"-C" specifies the target directory; typically programs are installed under /usr/local/.

3. Verify the installation

$ /usr/local/go/bin/go version

go version go1.17.1 linux/amd64

Environment Variable Configuration

After installation you still need to set environment variables, mainly GOROOT and GOPATH, to simplify command usage.

Check current Go environment:

$ /usr/local/go/bin/go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOPATH="/root/go"
GOROOT="/usr/local/go"
... (other variables omitted for brevity)

To understand each field, refer to the official documentation; for most projects you only need to know GOROOT and GOPATH.

Set the variables system‑wide so you can run go directly:

echo 'export GOROOT=/usr/local/go' >> /etc/profile
echo 'export GOPATH=$HOME/go' >> /etc/profile
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> /etc/profile

source /etc/profile

Now the go command works without the full path.

Modify Go environment variables using the go env -w flag, e.g.:

go env -w GOPATH=/path/to/your/go
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

These settings complete the Go environment configuration.

Article source: SegmentFault (copyright belongs to the original author).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backend DevelopmentGoEnvironment Variables
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.