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/localor 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
~/.profileor~/.bashrc:export PATH=$PATH:/usr/local/go/bin - Reload the shell configuration:
source ~/.profileorsource ~/.bashrc.
-
Verifying Installation:
- Verify Go installation by running
go versionin 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
gofolder to/usr/localor any directory of your choice. - Add Go binaries to your PATH by adding the following line to your
~/.profileor~/.bash_profile:export PATH=$PATH:/usr/local/go/bin - Reload the shell configuration:
source ~/.profileorsource ~/.bash_profile.
-
Verifying Installation:
- Verify Go installation by running
go versionin 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:\Goor any directory of your choice. - Add
C:\Go\binto thePathenvironment variable:- Right-click on
This PC->Properties->Advanced system settings->Environment Variables.... - Under
System Variables, findPath, clickEdit..., and addC:\Go\binto 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 versionin 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.,
~/goon Linux/macOS orC:\Users\YourUsername\goon Windows. - Set the
GOPATHenvironment variable to point to this directory:
orexport GOPATH=~/gosetx 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