Go, also known as Golang, is a programming language developed by Google that is widely used for building fast and efficient applications. Here are the steps to install Go on different operating systems.
System Requirements
Before starting the installation, make sure your system meets the following minimum requirements:
- Windows: Windows 7 or later
- macOS: macOS 10.10 or later
- Linux: Linux kernel 2.6.23 or later
Step 1: Download the Go Installer
You can download the latest version of Go from the official Go website at https://golang.org/dl/. Choose the installer that matches your operating system:
- Windows: Download the
.msifile - macOS: Download the
.pkgfile - Linux: Download the
.tar.gzfile
Step 2: Install Go
Install on Windows
-
Run the downloaded
.msifile. -
Follow the on-screen installation instructions.
-
Once the installation is complete, open
Command Promptand type the following command to verify the installation:go versionIf Go is installed successfully, you will see the installed version of Go.
Install on macOS
-
Open the downloaded
.pkgfile. -
Follow the on-screen installation instructions.
-
Once complete, open
Terminaland type the following command to verify the installation:go versionIf Go is installed successfully, you will see the installed version of Go.
Install on Linux
-
Extract the downloaded
.tar.gzfile to the/usr/localdirectory using the following command:sudo tar -C /usr/local -xzf go<version>.linux-amd64.tar.gz -
Add
/usr/local/go/binto thePATHvariable in your.profileor.bashrcfile:export PATH=$PATH:/usr/local/go/binThen reload the
.profileor.bashrcfile:source ~/.profile -
Verify the installation by typing the following command:
go versionIf Go is installed successfully, you will see the installed version of Go.
Step 3: Set Up Go Workspace
After installing Go, you need to set up your workspace. By default, the Go workspace is located at ~/go on Linux and macOS, or C:\Users\<username>\go on Windows.
-
Create the workspace directory if it does not already exist:
mkdir -p ~/go/{bin,pkg,src} -
Set
GOPATHto point to your workspace directory:export GOPATH=~/goAlso, add it to the
PATHvariable:export PATH=$PATH:$GOPATH/bin
Step 4: Run Your First Go Program
After Go is installed, you can create and run your first Go program:
-
Create a new directory inside
src:mkdir -p ~/go/src/hello -
Create a
hello.gofile with the following content:package main import "fmt" func main() { fmt.Println("Hello, World!") } -
Run the program:
go run hello.goYou will see the output "Hello, World!" in the terminal.
Now Go has been successfully installed on your system, and you have run your first Go program. You are ready to start learning and developing applications with Go. Happy coding!