How To Install Go in Linux

Created
Modified

Download Packages

Download packages for Windows 64-bit, macOS, Linux, and more.

Go install

Linux

Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extract the archive you just downloaded into /usr/local, creating a fresh Go tree in /usr/local/go:

install
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.18.1.linux-amd64.tar.gz

Add /usr/local/go/bin to the PATH environment variable. You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

#sudo vi /etc/.profile
#source /etc/.profile
export PATH=$PATH:/usr/local/go/bin
go
sudo vi /etc/.profile
source /etc/.profile
go version
go version go1.18.1 linux/amd64

Mac

Open the package file you downloaded and follow the prompts to install Go. The package installs the Go distribution to /usr/local/go. The package should put the /usr/local/go/bin directory in your PATH environment variable. You may need to restart any open Terminal sessions for the change to take effect.

Windows

Open the MSI file you downloaded and follow the prompts to install Go.

Installing Go from source

Most users don't need to do this, and will instead install from precompiled binary packages as described in Download and install. See: Installing Go from source

Try Go Online

You can try Go online in the Go Playground without installing anything on your computer. See: TRY GO WITHOUT INSTALLING

Go Help Commands and Options

Go is a tool for managing Go source code.

The commands are:
bug
start a bug report
build
compile packages and dependencies
clean
remove object files and cached files
doc
show documentation for package or symbol
env
print Go environment information
fix
update packages to use new APIs
fmt
gofmt (reformat) package sources
generate
generate Go files by processing source
get
add dependencies to current module and install them
install
compile and install packages and dependencies
list
list packages or modules
mod
module maintenance
run
compile and run Go program
test
test packages
tool
run specified go tool
version
print Go version
vet
report likely mistakes in packages
Use "go help <command>" for more information about a command. Additional help topics:
buildconstraint
build constraints
buildmode
build modes
c
calling between Go and C
cache
build and test caching
environment
environment variables
filetype
file types
go.mod
the go.mod file
gopath
GOPATH environment variable
gopath-get
legacy GOPATH go get
goproxy
module proxy protocol
importpath
import path syntax
modules
modules, module versions, and more
module-get
module-aware go get
module-auth
module authentication using go.sum
packages
package lists and patterns
private
configuration for downloading non-public code
testflag
testing flags
testfunc
testing functions
vcs
controlling version control with GOVCS
Use "go help <topic>" for more information about that topic.

Related Tags

#install# #go#