Installation
Updated: November 24, 2025
Steps of how to install Go.
Table of Contents
Linux
Arch/Manjaro
sudo pacman -S go
CentOS/RHEL
sudo yum install golang # CentOS 7
sudo dnf install golang # CentOS 8+
Fedora
sudo dnf install golang
NixOS
System-wide (configuration.nix)
Add to your configuration.nix:
environment.systemPackages = with pkgs; [
go
];
Temporary (nix-env)
nix-env -i go
Nix Shell
Create a shell.nix for project-specific Go environment:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
go
gopls # Go language server
delve # Go debugger
just # Command runner for justfile
];
shellHook = ''
echo "Go development environment loaded"
'';
}
Run with:
nix-shell
This provides all necessary tools including just for running the justfile recipes.
Nix Develop (Flakes)
For modern Nix setups using flakes, create a flake.nix in your project root:
{
description = "Go development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
go
gopls
delve
just
];
shellHook = ''
echo "Go development environment (flakes) loaded"
'';
};
});
}
Enable flakes in your Nix configuration and run:
nix develop
This provides the same tools as nix-shell but with flake-based dependency management.
Home Manager
Add to your ~/.config/nixpkgs/home.nix:
{ pkgs, ... }:
{
home.packages = with pkgs; [
go
gopls
delve
];
}
Example Justfile
Create a justfile in your project root for common tasks:
# Run tests
test:
go test ./...
# Build the project
build:
go build
# Run the application
run:
go run .
# Format code
fmt:
go fmt ./...
# Lint code
lint:
go vet ./...
# Clean build artifacts
clean:
go clean
# Install dependencies
deps:
go mod tidy
# Generate code
generate:
go generate ./...
Using the Justfile
Once you have just installed (included in the nix shell), you can run recipes from the command line:
just test # Run all tests
just build # Build the project
just run # Run the application
just fmt # Format code
just lint # Lint code
just clean # Clean build artifacts
just deps # Install/update dependencies
just generate # Generate code
Run just without arguments to see all available recipes. The justfile can be integrated with your nix shell environment for a complete development setup.
Tarball
- Download the Go tarball from the official website
- Extract it to /usr/local
sudo tar -C /usr/local -xzf ~/Downloads/go1.XX.X.linux-amd64.tar.gz
- Add Go to your PATH
export PATH=$PATH:/usr/local/go/bin
Add the export to your ~/.bashrc or ~/.zshrc for persistence.
macOS
Homebrew
brew install go
Windows
Chocolatey
choco install golang
MSI Installer
- Download the MSI installer from the official Go website
- Run the installer and follow the prompts
- Go will be installed to
C:\Program Files\Go\and added to PATH automatically
winget
winget install Go.Go
Setup
After installation, set up your Go workspace. Go 1.11+ uses modules by default, so GOPATH is optional.
Linux/macOS
mkdir ~/go
cd ~/go
mkdir src pkg bin # Only needed if using GOPATH
Set GOPATH if using older Go versions:
export GOPATH=$HOME/go
Add to ~/.bashrc or ~/.zshrc:
export PATH=$PATH:$HOME/go/bin
Windows
mkdir %USERPROFILE%\go
cd %USERPROFILE%\go
mkdir src pkg bin # Only needed if using GOPATH
Set GOPATH:
set GOPATH=%USERPROFILE%\go
Add to PATH (usually done by installer):
set PATH=%PATH%;%USERPROFILE%\go\bin
Create Your First Program
With modules (recommended):
mkdir hello
cd hello
go mod init hello
# Create main.go
go run main.go
With GOPATH:
cd ~/go/src # or %USERPROFILE%\go\src on Windows
mkdir hello
cd hello
# Create main.go
go run main.go