Welcome to our comprehensive guide on the Go Install Command! In this lesson, we'll walk you through the process of installing Go (also known as Golang) on your machine and setting up a development environment. By the end of this tutorial, you'll be ready to write, build, and run your own Go programs. 💡
Golang, or Go, is an open-source programming language developed by Google. It's known for its simplicity, efficiency, and strong support for concurrent programming. Go is used extensively in large-scale web applications, cloud services, and system programming.
Before we dive into installing Go, let's make sure your system meets the prerequisites:
Follow the steps below to install Go on your Linux or macOS machine:
curl -o go1.x.y.tar.gz https://go.googlesource.com/go/$(curl -s https://go.googlesource.com/go/v3/+archive/HEAD | grep -oP '(?<=tarball>)[^<]*')Replace 1.x.y with the latest Go version number. You can find the latest version on the Go Releases page.
tar -xvf go1.x.y.tar.gzsudo mv go go1.x.yOn Linux:
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
source ~/.bashrcOn macOS:
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bash_profile
source ~/.bash_profilego versionDownload the latest Go installer for Windows from the Go Downloads page. Choose the appropriate installer for your system (32-bit or 64-bit).
Run the downloaded installer and follow the on-screen instructions to install Go.
Once the installation is complete, open a new command prompt and verify the Go installation by checking the Go version:
go versionNow that Go is installed, let's write, build, and run our first Go program!
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}Save the code above in a file named main.go.
Open a terminal or command prompt and navigate to the directory containing main.go.
Build the program using the go build command:
go buildmain in the same directory. Run it using:./mainWhat is the name of the file that contains your Go program?