How To Install GoLang on Ubuntu 24.04

Published: 13 June 2024
on channel: Linux For Life
639
6

How to Install GoLang on Ubuntu 24.04

Description:

GoLang (or Go) is a popular open-source programming language designed for building fast and reliable software. This guide provides a comprehensive step-by-step approach to installing GoLang on Ubuntu 24.04 LTS Linux.

*Step-by-Step Guide:*

*Step 1: Update System Packages*

Before installing any new software, it's essential to update your system packages to their latest versions. Open a terminal and run:

```bash
sudo apt update
sudo apt upgrade -y
```

*Step 2: Download GoLang*

GoLang can be downloaded from the official GoLang website. Make sure to download the version that matches your operating system and architecture.

1. Visit the [official GoLang download page](https://golang.org/dl/).
2. Copy the download link for the latest version of GoLang for Linux.

Alternatively, you can download it directly using the terminal. For example, to download GoLang 1.20 (replace with the latest version if available):

```bash
wget https://golang.org/dl/go1.20.linux-am...
```

*Step 3: Install GoLang*

1. *Remove any previous Go installation:*

```bash
sudo rm -rf /usr/local/go
```

2. *Extract the downloaded tarball to /usr/local:*

```bash
sudo tar -C /usr/local -xzf go1.20.linux-amd64.tar.gz
```

*Step 4: Set Up GoLang Environment Variables*

To use GoLang, you need to set up the `GOPATH` and add GoLang to your `PATH`.

1. *Open your `.profile` file in a text editor:*

```bash
nano ~/.profile
```

2. *Add the following lines to set up GoLang environment variables:*

```bash
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
```

3. *Save and close the file.*

4. *Apply the changes:*

```bash
source ~/.profile
```

*Step 5: Verify the Installation*

To verify that GoLang is installed correctly, check the version:

```bash
go version
```

You should see output similar to this:

```plaintext
go version go1.20 linux/amd64
```

*Step 6: Create a Simple Go Program*

To ensure everything is set up correctly, create a simple Go program.

1. *Create a new directory for your Go projects:*

```bash
mkdir -p $GOPATH/src/hello
```

2. *Navigate to the new directory:*

```bash
cd $GOPATH/src/hello
```

3. *Create a new Go file named `hello.go`:*

```bash
nano hello.go
```

4. *Add the following code to `hello.go`:*

```go
package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}
```

5. *Save and close the file.*

*Step 7: Run the Go Program*

To compile and run your Go program, use the following command:

```bash
go run hello.go
```

You should see the output:

```plaintext
Hello, World!
```

*Conclusion:*

By following these steps, you have successfully installed GoLang on your Ubuntu 24.04 LTS Linux system and verified the installation with a simple program. Now you can start developing Go applications efficiently.

Don't forget to like, share, and subscribe for more tech tutorials and tips!

#GoLang #Ubuntu #Linux #Programming #TechTutorial #HowTo #GoProgramming #Ubuntu2404 #LinuxTips


Watch video How To Install GoLang on Ubuntu 24.04 online without registration, duration hours minute second in high quality. This video was added by user Linux For Life 13 June 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 639 once and liked it 6 people.