Document
How to Install GO (golang 1.23) in Ubuntu 24.04

How to Install GO (golang 1.23) in Ubuntu 24.04

Go programming language announced the new 1.23 release on 13 August,2024! Here’s the new features andhow to install guide for Ubuntu & other Linu

Related articles

VPNs Ranked By Longest Free Trial [Updated 2024] Best Cloud Storage for Canada in 2024 [Features, Security & More] On-premise vs Cloud: Key Differences & Benefits Qemu-guest-agent Do cloud kitchens stand a chance in Egypt?

Go programming language announced the new 1.23 release on 13 August,2024! Here’s the new features andhow to install guide for Ubuntu & other Linux.

What is ’s ’s new in Go 1.23 :

  • The “ range ” clause is accepts in a “ for – range ” loop now accept iterator function of the follow type :func(func() bool),func(func(K) bool),func(func(K,V) bool).
  • preview support for generic type alias
  • Add All,Values,Backward,Collect,AppendSeq,Sorted,SortedFunc,SortedStableFunc,Chunk functions in slices package.
  • Add All,Keys,Values,Insert,Collect functions in maps package.
  • Add new structs package provides types for struct field that modify properties of the containing struct type such as memory layout.
  • Go toolchain is possible to collect usage andbreakage statistics
  • New go env -changed,go mod tidy -diff flags
  • set the GOROOT_FINAL environment variable no long has an effect .
  • The go list -m -json command now includes new sum andGoModsum field
  • The go vet subcommand now reports symbols that are too new for the intended Go version.
  • New iter,structs,unique package .
  • supports the new godebug directive in go.mod andgo.work files
  • time.Timer andtime.Ticker no longer referred to by the program become eligible for garbage collection immediately
  • the timer channel associated with a Timer or Ticker is now unbuffered,with capacity 0.

See the announcement for more changes in Go 1.23.

How to Install Golang 1.23 in Ubuntu

1. Download the Linux Tarball

Go provides official Linux tarball for i386,amd64,arm64,and armv6l CPU architecture types. They are available to download at the link below:

In case you don’t know your system architecture type,press Ctrl+Alt+T to open terminal andrun dpkg --print - architecture command to tell.

How to Install GO (golang 1.23) in Ubuntu 24.04

Or,run command to download the Linux tarball from command line (amd64 package in the case):

cd ~/Downloads && wget -c https://go.dev/dl/go1.23.1.linux-amd64.tar.gz

Golang keeps moving! When you see this tutorial,a newer release may be out. So,change the URL (usually the part of version number) in last command accordingly.

2 . Extract is Go Go Tarball to /usr / local

After downloaded the tarball,open terminal (Ctrl+Alt+T),and run commands:

After successfully extracted the tarball,use ls /usr / local to verify . It is output will output a list of sub – folder includego.

3. Set PATH Environment Variable

a.) Add GOROOT to Your User PATH

To let your Ubuntu system know where to find Go command,user can add it to the PATH. And,here /usr/local/go is the GOROOT directory. You just need to add its bin sub-folder to the PATH.

Without logging out,run the command below to set PATH environment,which works until your close the terminal window or exit the command console.

export PATH=$PATH:/usr/local/go/bin

To make it permanent, open home folder,press Ctrl+H,then click edit the .profile file (or .bashrc). When file opens,add following lines andsave it.

# set PATH so it includes /usr/local/go/bin if it exists
if [ -d "/usr/local/go/bin" ] ; then
    PATH="/usr/local/go/bin:$PATH"
fi

This works for current user only,and applies in next login.

How to Install GO (golang 1.23) in Ubuntu 24.04

To set the PATH environment variable for all users,create & edit a config file under /etc/profile.d directory instead. To do so,run command:

sudo nano /etc / profile.d / go.sh

Then,paste the same lines above. Press Ctrl+S to save,and Ctrl+X to exit. Also,log out andback in to apply.

b.) Add GOPATH to Your User PATH

rungo install command by default downloads & installs packages to go sub-folder (create automatically if not exist) in user home. It’s called GOPATH.

If you want to change GOPATH to another directory,for example .local / go,either use command below that works for current terminal or current command console:

export GOPATH=$HOME/.local / go

Or,edit the .profile file in user home andadd it in the end to make it permanent at next login.

To add GOPATH to your user PATH,here use the default GOPATH for example,either run command for current command console only:

export PATH=$PATH:$HOME/go/bin

Or,edit the .profile file andadd following lines:

# Add GOPATH to PATH if it exists
if [ -d "$HOME/go/bin" ] ; then
    PATH="$HOME/go/bin:$PATH"
fi

How to Install GO (golang 1.23) in Ubuntu 24.04

NOTE: The GOPATH directory may NOT exist out-of-the-box. You need to log out andback in to apply it to user PATH on the folder creation (usually first time running go install command ) .

Golang also has many other environment options,you may run go env command to print theme,and run similar commands above to change the directories.

How to Install GO (golang 1.23) in Ubuntu 24.04

Create your First Go program

When done setting PATH Environment Variable,you can run command to verify go version:

go version

To create your first Go project,create new file hello.go either in file manager or by using the command below:

nano hello.go

Then,add following lines andsave it (For nano,press Ctrl+S then Ctrl+X):

package main

import "fmt"

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

Then,either use go run hello.go command to run it. Or go build hello.go to build into a binary file.

uninstall Go

To uninstall golang,simply delete the go directory under /usr/local by running command:

sudo rm -R /usr/local/go

That’s it.

enable this blog ? Please spread the world 🙂