This tutorial provides a step-by-step guide to installing Go (Golang) on Rocky Linux 8 and creating a simple Go program, enabling you to start developing applications using the Go programming language.
Micro
VPS
1
vCPU
2 GB
Memory
20 GB
NVMe Disk
1024 GB
Traffic
4.90€
/month
* Up to 6GB RAM, 60GB NVMe Disk Space and 1Gbit/s Network Speed
#### Prerequisites
Before you begin, ensure you have:
- A server running Rocky Linux 8 (This guide is tested with Rocky Linux 8)
- A user account with sudo privileges
- Basic familiarity with the command line
#### Step 1: Install Go (Golang)
First, download the latest stable version of Go from the official website:
```bash
wget https://golang.org/dl/go1.18.5.linux-amd64.tar.gz
```
Extract the downloaded archive and install Go to `/usr/local`:
```bash
sudo tar -C /usr/local -xzf go1.18.5.linux-amd64.tar.gz
```
#### Step 2: Set Go Environment Variables
Set Go environment variables by adding them to your shell configuration file (e.g., `~/.bashrc` or `~/.profile`):
```bash
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc
```
#### Step 3: Verify Go Installation
Verify that Go is installed correctly by checking the version:
```bash
go version
```
#### Step 4: Create a Simple Go Program
Create a directory for your Go workspace and navigate into it:
```bash
mkdir -p ~/go/src/hello
cd ~/go/src/hello
```
Create a new Go file `hello.go` and open it with a text editor:
```bash
nano hello.go
```
Add the following Go code to `hello.go`:
```go
package main
import "fmt"
func main() {
fmt.Println("Hello, Go on Rocky Linux 8!")
}
```
Save and close the file.
#### Step 5: Build and Run the Go Program
Build the Go program using the `go build` command:
```bash
go build
```
Run the executable generated:
```bash
./hello
```
You should see the output:
```
Hello, Go on Rocky Linux 8!
```
#### Conclusion
You have successfully installed Go (Golang) on Rocky Linux 8 and created a simple Go program. Begin exploring more features of Go and developing applications using this powerful programming language.
**Additional Resources:**
- **Official Go Documentation:** [https://golang.org/doc/](https://golang.org/doc/)
- **Rocky Linux Documentation:** [https://docs.rockylinux.org/](https://docs.rockylinux.org/)