
{{ $('Map tags to IDs').item.json.title }}
How to Install Go (Golang) and Write Your First Program
Go, also known as Golang, is an open-source programming language designed for simplicity, efficiency, and good performance at scale. This tutorial will guide you through installing Go on your system and writing your first program.
Prerequisites
- Basic understanding of programming concepts.
- A system with internet access to download Go.
1. Downloading Go
Visit the official Go programming language website at golang.org/dl, and download the appropriate archive for your operating system (Windows, macOS, Linux).
1.1. Installing on Linux
For Linux, you can download and install using the following commands in your terminal:
wget https://golang.org/dl/go1.17.6.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.17.6.linux-amd64.tar.gz
Make sure to replace 1.17.6
with the latest version available.
2. Setting Up Environment Variables
To use Go, you need to add its binary to your PATH. Open your profile file:
nano ~/.bash_profile
And add the following line:
export PATH=/usr/local/go/bin:$PATH
Save the file and apply the changes:
source ~/.bash_profile
2.1. Verify the Installation
To check if Go is installed correctly, run:
go version
You should see the installed version of Go displayed in the terminal.
3. Writing Your First Go Program
Now, let’s write a simple Go program. Create a new directory for your Go projects:
mkdir ~/go_projects
cd ~/go_projects
Create a file named hello.go
using your preferred text editor:
nano hello.go
Add the following code to hello.go
:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
4. Running Your Go Program
To run your first Go program, use the following command in your terminal:
go run hello.go
You should see the output:
Hello, World!
5. Compiling Your Go Program
To compile your Go program into an executable, run:
go build hello.go
This will create an executable named hello
(or hello.exe
on Windows). You can run it using:
./hello
6. Conclusion
By following this tutorial, you have successfully installed Go on your Linux system and created your first Go program. Go is a powerful language that supports concurrency and efficient performance, making it ideal for modern applications. Explore more of its features and the extensive ecosystem to enhance your programming skills!