GOLANG SETUP IN LINUX
Quick Introduction About Golang
Golang or Go is a procedural programming language. It originally developed by Rob Pike, Robert Griesemer and Ken Thompson at Google however launched after two years as an open-source programming language. Programs are assembled by packages, for efficient management of dependencies. Golang also supports the environment adopting patterns alike to dynamic languages. For e.g., type inference (y := 0 could be a valid declaration of a variable y of type float).
Purpose of this article?
As we know Golang is one of the most popular languages nowadays. Today we will learn how to set up Golang in the Linux operating system with VS Code and then also make a demo project.
Let’s Begin
Install Golang
Upgrade to apply the latest security updates on the Linux operating system.
sudo apt-get update sudo apt-get upgrade
- You need to download the Go binary file. Visit on https://golang.org/dl/ for download Golang binary file.
- Extract download binary file on your preferable location on the system. I’m extracting it under
/usr/local
directory as suggested by standards.
sudo tar -C /usr/local -xzf go1.14.1.linux-amd64.tar.gz
Set up a Golang environment.
- Open
.bahrc
file and add the below code in that file.
export PATH=$PATH:/usr/local/go/bin
- Now check your configuration
- You have successfully configured the Go language on your system.
To check the Go version:
go version //as output you will get the version of Golang
Install VSCode
- I’m installing VSCode by Snap you can download other ways too.
sudo snap install vscode --classic
- Open VSCode by using the below command.
snap run vscode
- Open VS Code and go to Extensions and search Go then install it.
We have done all the setup that we will need. Now we’re creating a new file with “.go” extension and write code for the print square root of a number on a console. i.e. if you create a file by the name of first then your file should be first.go
package main import( "fmt" "math" ) func main() { fmt.Println(math.Sqrt(36)) }