Go or Golang is a free and open source concurrent, functional, imperative and object-oriented programming language for Linux, macOS, Windows, BSD and created by Google. It comes with some advantages like memory safety, garbage collection and structural typing. Some famouse projects written in Go are Docker and Kubernetes, Google’s download server, hootsuite, Crowdfire and many more. Emacs, Vim, VSCode, Atom, Eclipse, Sublime and IntelliJ provides support for go language.
Install Go programming language on Ubuntu:
Go to the above go language download page and download the latest Linux version. Here the downloaded file name is “go1.20.2.linux-amd64.tar.gz”. Right click on this file and select Extract Here option. You will get “go” folder.
Then open your file manager in root mode. If you are using nautilus file manager, then use this command.
sudo -E nautilus
If your file manager is thunar (xfce), then
sudo -E thunar
Then copy the go directory and paste it to the /usr/local folder.
[Or]
You can also do this all above steps by running below command in your terminal app. Open the terminal (ctrl+alt+t) and run below command.
wget -c https://dl.google.com/go/go1.20.2.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
Here the current go version is 1.20.2 and go download url for the Linux version is https://go.dev/dl/go1.20.2.linux-amd64.tar.gz You can change this url based on your download link. you can check this from above go binary download link.
Add Go Folder Path to the $PATH environment:
In terminal
export PATH=$PATH:/usr/local/go/bin
source ~/.profile
Restart your system and verify the installation by
go version
If you get any error. run this again.
export PATH=$PATH:/usr/local/go/bin
source ~/.profile
Run Go Hello World Program:
Create go/src/connectwww folder inside username folder. Or run this command to create it.
mkdir -p ~/go/src/connectwww
Navigate to the created connectwww folder and create a file called “connectwww.go”
Open that file with any text editor and write the below code and save it.
package main import ( "fmt" ) func main() { fmt.Println("Hello, CONNECTwww.com") }
Then run this command
go env -w GO111MODULE=auto
Then navigate to go/src/connectwww in terminal.
cd go/src/connectwww
Then build the program using below cmomand.
go build
Then run
./connectwww