Otu esi etinye ihe nchịkọta Go (Golang) na Ubuntu 20.04

Go, ma ọ bụ Golang bụ asụsụ mmemme mepere emepe nke Google mepụtara. A na-apịpụta ya nke ọma wee mepụta ọnụọgụ koodu igwe agbakọtara. Go asụsụ bụ asụsụ achịkọtara. Nke a na-ewu ewu n'etiti ndị nrụpụta n'ihi na ọ pụtaghị na ịchọghị ikpokọta koodu isi mmalite iji mepụta faịlụ enwere ike ime ya. Ndị mmepe na-eji asụsụ Google Go na-ekwu na ọ bụ C maka narị afọ nke iri abụọ na otu ma a bịa na syntax.

Ị ga -ama otu esi etinye ma hazie Go (Golang) na Ubuntu 20.04 LTS Focal Fossa gị Sistemụ arụmọrụ na ntuziaka na-esonụ. Otu ụkpụrụ ahụ ga-arụ ọrụ maka ụdị ọhụrụ Ubuntu 21.04 (Hirsute Hippo).

Ihe ndi choro

  • OS akwadoro: Ubuntu 20.04 - nhọrọ (Ubuntu 21.04 na Linux Mint 20)
  • Akaụntụ onye ọrụ: Akaụntụ onye ọrụ nwere sudo ma ọ bụ ohere mgbọrọgwụ.

Tupu ịmalite, jide n'aka na usoro Ubuntu 20.04 LTS Focal Fossa dị ọhụrụ:

sudo apt update && sudo apt upgrade -y

Gbaa mbọ hụ na etinyere ngwungwu wget na sistemụ arụmọrụ:

sudo apt install wget

Advertisement


Wụnye Go (Goland)

Ị nwere ike iwunye Go (Golang) n'ụzọ abụọ, site na onye njikwa ngwugwu kwesịrị ekwesị sitere na ebe nchekwa Ubuntu, na nke abụọ site na ịgbakwunye ebe nchekwa isi iyi, nke a na-atụ aro maka mmelite ngwa ngwa na njirimara.

Onye njikwa ngwugwu dabara adaba

Mepee ọnụ (Ctrl+ALT+T) ma mezuo iwu na-esonụ:

sudo apt install golang

Ị ga-enweta nsonaazụ nke ngwugwu ndị ọzọ Go ga-wụnye:

joshua@ubuntu:~$ sudo apt install golang
 [sudo] password for joshua: 
 Reading package lists… Done
 Building dependency tree       
 Reading state information… Done
 The following additional packages will be installed:
   binutils binutils-common binutils-x86-64-linux-gnu g++ g++-9 gcc gcc-9
   golang-1.13 golang-1.13-doc golang-1.13-go golang-1.13-race-detector-runtime
   golang-1.13-src golang-doc golang-go golang-race-detector-runtime golang-src
   libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcrypt-dev
   libctf-nobfd0 libctf0 libgcc-9-dev libitm1 liblsan0 libquadmath0
   libstdc++-9-dev libtsan0 libubsan1 linux-libc-dev manpages-dev
 Suggested packages:
   binutils-doc g++-multilib g++-9-multilib gcc-9-doc gcc-multilib make
   autoconf automake libtool flex bison gcc-doc gcc-9-multilib gcc-9-locales
   bzr | brz git mercurial subversion glibc-doc libstdc++-9-doc
 The following NEW packages will be installed:
   binutils binutils-common binutils-x86-64-linux-gnu g++ g++-9 gcc gcc-9
   golang golang-1.13 golang-1.13-doc golang-1.13-go
   golang-1.13-race-detector-runtime golang-1.13-src golang-doc golang-go
   golang-race-detector-runtime golang-src libasan5 libatomic1 libbinutils
   libc-dev-bin libc6-dev libcrypt-dev libctf-nobfd0 libctf0 libgcc-9-dev
   libitm1 liblsan0 libquadmath0 libstdc++-9-dev libtsan0 libubsan1
   linux-libc-dev manpages-dev
 0 upgraded, 34 newly installed, 0 to remove and 0 not upgraded.
 Need to get 96.9 MB of archives.
 After this operation, 482 MB of additional disk space will be used.
 Do you want to continue? [Y/n] 

Pịnye na-abanye (NA) ịga n'ihu nrụnye, na n'ozuzu ya kwesịrị iwepụta nkeji ole na ole, ma ọ bụrụ na ọ bụghị ngwa ngwa.

Na-esote, ka imecha ya, lelee ụdị ngwanrọ iji hụ ihe ị nọ na ọ bụrụ na ọ dị nso nso a maka ihe ị chọrọ:

go version

mmepụta:

joshua@ubuntu:~$ go version
 go version go1.13.8 linux/amd64

Ọ bụrụ na ụdị ahụ dị oke n'azụ, tinyezie Go site na isi mmalite, dị ka egosiri n'akụkụ nke ọzọ nke ntuziaka anyị.

Wụnye isi mmalite

Budata ụdị Go kachasị ọhụrụ site na webụsaịtị gọọmentị ha site na iji iwu a:

wget https://golang.org/dl/go1.16.5.linux-amd64.tar.gz

Mara, n'oge ntuziaka a, ụdị 1.16.5 bụ nke kachasị ọhụrụ. Gaa na ibe nbudata ka ịlele ọnụọgụ ụdị wee jiri nke emelitere dochie URL ma ọ bụrụ na ọ dị.

Ozugbo ebudatara Go, wepụ faịlụ ebudatara na faịlụ /usr/local/ directory:

tar -xzf go1.16.5.linux-amd64.tar.gz -C /usr/local/

Ugbu a, ị ga-achọ ịgbakwunye ụzọ ndekọ aha Go na $ ATzọ mgbanwe na / wdg / profaịlụ ndekọ site na iji ndezi ederede ọkacha mmasị anyị nano:

sudo nano /etc/profile

Ozugbo faịlụ ahụ mepere, tinyezie ahịrị a (CTRL+O) ịzọpụta, na (CTRL+X) ịpụ apụ ozugbo emechara:

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

Na-esote, rụọ ọrụ mgbanwe gburugburu PATH nke ị gbakwụnyere. Pịnye iwu a:

source /etc/profile

Na-esote, dị ka ọ dị na mbụ iji nwụnye njikwa ngwugwu dabara adaba, lelee ụdị:

go version

mmepụta:

joshua@ubuntu:~$ go version
 go version go1.16.5 linux/amd64

Otu esi eji Go - Mepụta mmemme.

Ugbu a ị tinyela Go, anyị ga-emepụta obere mmemme nke ga-ebipụta (Ndewo Ụwa).

Mbụ, mepụta ndekọ:

sudo mkdir go-hello

Ugbu a, ị ga-emepụta faịlụ (.go). Ụzọ kachasị mfe iji mee nke a bụ iji nchịkọta akụkọ nano:

sudo nano go-hello/hello.go

Na-esote, tinye ederede n'okpuru ka ịmepụta ya (Ndewo Ụwa) Gaa mmemme:

package main

import "fmt"

func main() {
     fmt.Printf("Hello, World\n") 
}

Chekwaa faịlụ (Ctrl+O), wee pụọ (CTRL+X).

Ugbu a, ịkwesịrị ịrụ ụlọ (go.mod) faịlụ ka ị nwee ike mebe faịlụ Go nke ị mebere:

sudo nano go-hello/go.mod

Tinye ahịrị na-esonụ:

module example.com/mod

Ugbu a, chekwaa faịlụ ahụ (CTRL+O) wee pụọ (CTRL+X).

Na-esote, cd gaa na ndekọ, wee wuo mmemme site na itinye iwu a:

cd go-hello && go build

N'ikpeazụ, mebie mmemme (Hello World) site na itinye iwu a:

./mod

Ị ga - enweta mmepụta ndị a:

Hello, World!

Advertisement


Okwu na mmechi:

N'ime ntuziaka ahụ, ị ​​mụtala otu esi etinye Go (Galang) nke ọma na-eji ma Ubuntu ndabere ndabere ma ọ bụ kpọmkwem site na isi iyi (Akwadoro) wee mepụta mmemme Go nke mbụ gị nke ọma.

Maka ozi ndị ọzọ maka iji na ịzụlite na Go, gaa na onye ọrụ gọọmentị akwụkwọ.

Ọ bụrụ na ị nwere ajụjụ, nweere onwe gị ịhapụ ikwu okwu n'okpuru.

Idenye aha
Gwa nke
0 Comments
Inline nzaghachi
Lee echiche niile
0
Ga-ahụ n'anya gị echiche, biko okwu.x