How to install Go (Golang) on various operating systems
Installing Go (Golang) on various operating systems is straightforward. Here are the general steps for installing Go on different OS platforms:
Installing Go on Linux
-
Using Package Manager (recommended for most Linux distributions):
- Open your terminal.
- Update your package index:
sudo apt update
(for Debian/Ubuntu) or equivalent for other distributions. - Install Go using the package manager:
sudo apt install golang
(for Debian/Ubuntu).
-
Using Binary Distribution:
- Download the Go binary distribution from the official website: https://golang.org/dl/
- Extract the downloaded archive to
/usr/local
or any directory of your choice.sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
- Add Go binaries to your PATH by adding the following line to your
~/.profile
or~/.bashrc
:export PATH=$PATH:/usr/local/go/bin
- Reload the shell configuration:
source ~/.profile
orsource ~/.bashrc
.
-
Verifying Installation:
- Verify Go installation by running
go version
in the terminal.
- Verify Go installation by running
Installing Go on macOS
-
Using Homebrew (recommended):
- Open your terminal.
- Install Go using Homebrew:
brew install golang
-
Using Binary Distribution:
- Download the Go binary distribution from the official website: https://golang.org/dl/
- Mount the downloaded disk image and drag the
go
folder to/usr/local
or any directory of your choice. - Add Go binaries to your PATH by adding the following line to your
~/.profile
or~/.bash_profile
:export PATH=$PATH:/usr/local/go/bin
- Reload the shell configuration:
source ~/.profile
orsource ~/.bash_profile
.
-
Verifying Installation:
- Verify Go installation by running
go version
in the terminal.
- Verify Go installation by running
Installing Go on Windows
-
Using MSI Installer (recommended):
- Download the MSI installer from the official website: https://golang.org/dl/
- Run the installer and follow the prompts to complete the installation.
-
Using Archive (zip) Distribution:
- Download the zip archive from the official website.
- Extract the contents to
C:\Go
or any directory of your choice. - Add
C:\Go\bin
to thePath
environment variable:- Right-click on
This PC
->Properties
->Advanced system settings
->Environment Variables...
. - Under
System Variables
, findPath
, clickEdit...
, and addC:\Go\bin
to the list.
- Right-click on
- Open a new Command Prompt (cmd) and verify Go installation by running
go version
.
-
Verifying Installation:
- Verify Go installation by running
go version
in the Command Prompt.
- Verify Go installation by running
Setting Up GOPATH (Optional but recommended)
- Go requires a workspace directory (
GOPATH
) to store your Go projects and dependencies. It's recommended to set upGOPATH
:- Create a directory for your Go workspace, e.g.,
~/go
on Linux/macOS orC:\Users\YourUsername\go
on Windows. - Set the
GOPATH
environment variable to point to this directory:
orexport GOPATH=~/go
setx GOPATH "C:\Users\YourUsername\go"
- Create a directory for your Go workspace, e.g.,
This setup allows you to manage and run your Go projects effectively. After installation, you can start developing Go applications and use tools like go build
, go run
, and go get
to manage dependencies.
Published on: Jun 19, 2024, 11:19 PM