Saturday, August 21, 2021

How To Install Go Lang on Debian 11 / Debian 10


Go is a programming language designed by Google engineers Robert Griesemer, Rob Pike, and Ken Thompson. It is primarily intended to be a modern language: it doesn't have constructs that make you remember your past (like C's structs) or are inspired by other languages (like Python's list comprehensions).

Go's major features are: memory safety without a garbage collector, concurrency without data races, deadlock freedom, and coordination avoidance.

Here, we will see how to install Golang on Debian 11 / Debian 10.

Download and Install Go Language

Install wget package.
sudo apt update sudo apt install wget -y

Visit the Go Language download page to download the latest version of Go. Alternatively, you can download the Go language binary package via terminal using the following command.
wget https://golang.org/dl/go1.17.linux-amd64.tar.gz

Extract the archive to /usr/local.
sudo tar -zxvf go1.17.linux-amd64.tar.gz -C /usr/local/

Setup Go Environment

We will now configure the PATH environment variable to include Go's bin (/usr/local/go/bin) directory. To do that, execute the below command.

For the system-wide installation and load the environment onto your current login session, run the following command.
echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee /etc/profile.d/go.sh source /etc/profile.d/go.sh

For your specific profile and load the environment onto your current login session, run the following command.
echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee -a $HOME/.profile source $HOME/.profile

Verify Go Installation

Run the below command to see the version of the Go language.
go version

Output:
go version go1.17 linux/amd64

Check the Go environment variables we set in previous sections.
go env 

Output:
GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/debian/.cache/go-build" GOENV="/home/debian/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/debian/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/debian/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.17" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/dev/null" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1429786228=/tmp/go-build -gno-record-gcc-switches" 

Create First Project

Create a directory hello under your home directory.
mkdir -p hello cd hello

Let's create a simple program (hello) to test the Go installation.

vi hello.go

Place the following content in the hello.go file.
package main import "fmt" func main() { fmt.Printf("Welcome To ITzGeek\n") }

Now, run the code with the go command.
go run .

You would get the following greeting text.
Welcome To ITzGeek

Sumber: disini

0 comments:

Post a Comment