Skip to main content

How to Install Golang in Linux



Install Golang In Linux Using Update-golang Script 

 Download the Update-golang script by cloning its repository from GitHub:
$ git clone https://github.com/udhos/update-golang
The above command will clone the contents of official update-golang repository in a local directory named update-golang. Cd into this directory:
$ cd update-golang
It is always recommended to check the integrity of a script downloaded from Internet. So let us do that by verifying the CHECKSUM value of update-golang script:
$ wget -qO hash.txt https://raw.githubusercontent.com/udhos/update-golang/master/update-golang.sh.sha256
$ sha256sum -c hash.txt
If you get an output as OK, you're good to go.
update-golang.sh: OK
After verifying the chekcsum, run the following command to install latest Golang version on your Linux machine:
$ sudo ./update-golang.sh
Sample output:

update-golang.sh: version 0.24
update-golang.sh: find_latest: found last release: 1.16.2
update-golang.sh: user: uid=0(root) gid=0(root) groups=0(root)
update-golang.sh: RELEASE_LIST=https://golang.org/dl/
update-golang.sh: SOURCE=https://storage.googleapis.com/golang
update-golang.sh: DESTINATION=/usr/local
update-golang.sh: RELEASE=1.16.2
update-golang.sh: OS=linux
update-golang.sh: ARCH_PROBE=uname -m
update-golang.sh: ARCH=amd64
update-golang.sh: PROFILED=/etc/profile.d/golang_path.sh
update-golang.sh: CACHE=/usr/local
update-golang.sh: GOPATH=
update-golang.sh: DEBUG=
update-golang.sh: 
update-golang.sh: will install golang go1.16.2.linux-amd64 as: /usr/local/go
update-golang.sh: https://storage.googleapis.com/golang/go1.16.2.linux-amd64.tar.gz is remote
--2021-03-30 06:02:35--  https://storage.googleapis.com/golang/go1.16.2.linux-amd64.tar.gz
Resolving storage.googleapis.com (storage.googleapis.com)... 2404:6800:4009:81f::2010, 2404:6800:4009:820::2010, 2404:6800:4009:81d::2010, ...
Connecting to storage.googleapis.com (storage.googleapis.com)|2404:6800:4009:81f::2010|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 129010536 (123M) [application/octet-stream]
Saving to: ‘/usr/local/go1.16.2.linux-amd64.tar.gz’

/usr/local/go1.16.2.linux-amd64.t 100%[=============================================================>] 123.03M   501KB/s    in 5m 2s   

2021-03-30 06:07:40 (417 KB/s) - ‘/usr/local/go1.16.2.linux-amd64.tar.gz’ saved [129010536/129010536]

update-golang.sh: remove_old_link: not found symlink for old install
update-golang.sh: untar: tar -x -f /usr/local/go1.16.2.linux-amd64.tar.gz
update-golang.sh: profile_path_add: issuing new /usr/local/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: profile_path_add: issuing $HOME/go/bin to /etc/profile.d/golang_path.sh
update-golang.sh: golang go1.16.2.linux-amd64 installed at: /usr/local/go
update-golang.sh: testing: /usr/local/go/bin/go version
update-golang.sh: unsudo: running_as_root:ostechnix: /usr/local/go/bin/go version
update-golang.sh: go version go1.16.2 linux/amd64
update-golang.sh: /usr/local/go/bin/go version: SUCCESS
update-golang.sh: unsudo: running_as_root:ostechnix: mktemp -t hello-tmpXXXXXXXX
update-golang.sh: unsudo: running_as_root:ostechnix: tee /tmp/hello-tmpqGBVcjhy.go
update-golang.sh: testing: /usr/local/go/bin/go run /tmp/hello-tmpqGBVcjhy.go
update-golang.sh: unsudo: running_as_root:ostechnix: /usr/local/go/bin/go run /tmp/hello-tmpqGBVcjhy.go
update-golang.sh: hello, world
update-golang.sh: /usr/local/go/bin/go run /tmp/hello-tmpqGBVcjhy.go: SUCCESS
update-golang.sh: running_as_root: yes
update-golang.sh: recursively forcing build cache [/home/ostechnix/.cache/go-build] ownership to 1000:1000
Install Golang In Linux Using Update-golang Script
Install Golang In Linux Using Update-golang Script

Check Golang version and environment information 


 To verify the installed Go version, run:
 go version
go version go1.16.2 linux/amd64
As you can see, Update-golang script has installed Go version 1.16.2. This is the latest, stable Go version at the time of writing this guide. To print Go environment information, run:
$ go env
Sample output:

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ostechnix/.cache/go-build"
GOENV="/home/ostechnix/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ostechnix/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ostechnix/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.16.2"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build883237217=/tmp/go-build -gno-record-gcc-switches"

Install Golang beta or release candidate (RC) version 


 By default, Update-golang script will install the latest stable version. If you want to install any beta or release candidate versions, explicitly mention the version like below: Install Golang beta:
$ sudo RELEASE=1.9beta1 ./update-golang.sh
Install release candidate (RC):
$ sudo RELEASE=1.11rc1 ./update-golang.sh
Golang per-user installation By default, Update-golang script installs Golang system-wide. If you want to install Golang for current user, simply create a installation directory, for example ~/golang:
$ mkdir ~/golang
And then install GO using command:
$ DESTINATION=~/golang PROFILED=~/.profile ./update-golang.sh
Please note that per-user installation does not need root or sudo permission. Prevent caching downloaded files As mentioned earlier, Update-golang script will keep the downloaded archives in /usr/local directory. If you don't want cache the archive files, simply use -declutter option:
$ sudo ./update-golang.sh -declutter
This time the installation files will not be cached. 

 Remove Golang


 To undo all steps done by Update-golang script, go to the cloned directory and run:
$ sudo ./update-golang.sh remove
This command will remove Go and all related entries from the $PATH.
update-golang.sh: version 0.24
update-golang.sh: find_latest: found last release: 1.16.2
update-golang.sh: remove: found symlink for old install: /usr/local/go1.16.2.linux-amd64
update-golang.sh: remove: removing symlink: /usr/local/go
update-golang.sh: remove: removing dir: /usr/local/go1.16.2.linux-amd64
update-golang.sh: profile_path_remove: removing old settings from: /etc/profile.d/golang_path.sh

Comments

Popular posts from this blog

Cara Disable Antimalware Service Executable di Windows 10

Disadari atau tidak, Windows 10 (dan juga windows-windows lainnya) hadir dengan banyak sekali aplikasi bloatware (aplikasi yang tidak perlu-perlu amat dimiliki oleh end user). Contohnya, adalah aplikasi yang seharusnya sudah tergantikan fungsinya oleh antivirus, seperti Antimalware Service Executable . Aplikasi ini dicurigai membuat Windows 10 mengalami inefisiensi memori/RAM, memakan resource yang tinggi, dengan Load yang tinggi (tanpa limit terkadang). Nah, berikut adalah cara men-disable nya: Tekan tombol Windows + I untuk membuka apliaksi Windows Setting. Pilih icon menu Update and Security Pilih lagi menu disamping kiri Windows Security Pada jendela baru yang muncul, ada pilihan Virus & Threat protection Klik ini Lalu matikan proses Real-time protection tersebut. Dengan Regedit. Buka dialog regedit, Windows + R dan ketik ‘regedit’ Cari Folder regedit ini HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows Defender Buat sebuah DWORD baru dengan klik kanan

Setup Debian 11 Official Repository In sources.list (/etc/apt/sources.list)

When you install Debian 11 using a DVD, the OS installer sets the DVD as the source for getting packages for your system if you didn't choose to scan for network mirrors. Due to this reason, the system would ask you to insert a DVD if the disc is not present in the DVD drive when you try to install any software.  Also, the packages on DVD may not be the latest release.  So, we need to get the packages from the Internet. Media change: please insert the disc labeled 'Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04' in the drive '/media/cdrom/' and press [Enter] The /etc/apt/sources.list file with DVD as a source would look something like below. # deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb cdrom:[Debian GNU/Linux 11.0.0 _Bullseye_ - Official amd64 DVD Binary-1 20210814-10:04]/ bullseye contrib main deb http://security.debian.org/debian-security bullseye-security

Cara Membuat Live USB VMWare ESXi 6.7 di Linux (Debian/CentOS)

VMWare ESXi 6.7 menyediakan satu installer dalam format CDROM ISO. Dalam tutorial kali ini kita akan membuat sebuah live USB dengan menggunakan sistem Linux, misalnya Debian dan CentOS. Untuk keperluan tutorial kali ini silakan pastikan sudah ada download installer ISO ESXi 6.7 dari https://my.vmware.com Siapkan satu USB Flashdisk dengan kapasitas lebih dari 1GB. Format dalam satu partisi dengan tool yang biasa dipakai dalam format partisi FAT32. Misal dengan FDISK: [sourcecode] fdisk /dev/sdX [/sourcecode] format ke FAT32: [sourcecode]mkfs.fvat -F 32 -n USB /dev/sdX1[/sourcecode] selanjutnya, kita buat USB tersebut bootable dengan syslinux. Bagi linuxnya belum ada syslinux, silakan install dulu (apt-get install syslinux atau yum install syslinux).