1. Ubuntu (Linux)
Step 1: Update Package Index
1sudo apt update
Step 2: Install Go
1sudo apt install golang-go
Step 3: Verify Installation
1go version
Step 4: Set Up Workspace
- Create a directory for your Go projects:
1mkdir ~/go_projects
- Set the
GOPATH
environment variable in~/.bashrc
or~/.profile
:
1echo "export GOPATH=$HOME/go_projects" >> ~/.bashrc
2echo "export PATH=$PATH:$GOPATH/bin" >> ~/.bashrc
3source ~/.bashrc
2. Windows
Step 1: Download Go Installer
- Go to the official Go download page and download the Windows installer.
Step 2: Run the Installer
- Double-click the downloaded
.msi
file and follow the installation instructions.
Step 3: Verify Installation
- Open Command Prompt and run:
1go version
Step 4: Set Up Workspace
- Create a directory for your Go projects, e.g.,
C:\go_projects
. - Set the
GOPATH
environment variable:- Right-click on "This PC" → Properties → Advanced system settings → Environment Variables.
- Add a new variable named
GOPATH
with the path to your project directory. - Edit the
Path
variable to include%GOPATH%\bin
.
3. macOS
Step 1: Install Homebrew (if not already installed)
- Open Terminal and run:
1/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install Go
1brew install go
Step 3: Verify Installation
1go version
Step 4: Set Up Workspace
- Create a directory for your Go projects:
1mkdir ~/go_projects
- Set the
GOPATH
environment variable in your shell profile (~/.bash_profile
,~/.zshrc
, etc.):
1echo "export GOPATH=$HOME/go_projects" >> ~/.zshrc
2echo "export PATH=$PATH:$GOPATH/bin" >> ~/.zshrc
3source ~/.zshrc
Final Steps for All Platforms
- You can create your first Go file to test your setup:
1// main.go
2package main
3
4import "fmt"
5
6func main() {
7 fmt.Println("Hello, World!")
8}
- Run your program:
1go run main.go
This concludes the setup process for Go development on Ubuntu, Windows, and macOS.