This repository contains a simple "Hello World" program written in Go. It's a great starting point for learning Go, a modern programming language designed for efficiency and simplicity.
- Go Installation: Ensure you have Go installed on your system.
-
Download Go:
- Visit the official Go website: https://golang.org/dl/
- Download the version appropriate for your operating system.
-
Install Go:
- Windows: Run the
.msiinstaller and follow the instructions. - macOS: Use the
.pkgfile or install via Homebrew:brew install go
- Linux: Extract the downloaded tarball and move it to
/usr/local:tar -C /usr/local -xzf go1.xx.x.linux-amd64.tar.gz export PATH=$PATH:/usr/local/go/bin
- Windows: Run the
-
Verify Installation:
go version
Create a new file named main.go and add the following code:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}-
Navigate to your project directory:
cd /path/to/your/project -
Build the executable:
go build main.go
-
Linux/macOS: Produces an executable named
main(or the filename of your.gofile).- Run the program:
./main
- Run the program:
-
Windows: Produces an executable named
main.exe.- Run the program:
.\main.exe
- Run the program:
go buildcompiles the code and creates an executable in the current directory.- Cross-platform compatibility: Go allows building binaries for different operating systems. You can set environment variables to target other platforms:
GOOS=windows GOARCH=amd64 go build main.go