Otu esi etinye ihe nchịkọta Go (Golang) na Debian 11

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 n'okwu syntax.

N'ime ntuziaka na-esonụ, ị ga-ama otu esi etinye ma hazie Go (Golang) na Debian 11 Bullseye gị sistemụ nrụọrụ.

Prerequisites

  • OS akwadoro: Nnenna 11 Bullseye.
  • Akaụntụ onye ọrụ: Akaụntụ onye ọrụ nwere sudo ihe ùgwù or ohere mgbọrọgwụ (su Command).

Na-emelite Sistemụ Ọrụ

Melite gi Debian 11 Sistemụ arụmọrụ iji hụ na ngwugwu niile dị adị adịla ugbu a:

sudo apt update && sudo apt upgrade

Mgbọrọgwụ ma ọ bụ Sudo Access

Site na ndabara, mgbe ị mepụtara akaụntụ gị na mmalite na Debian ma e jiri ya tụnyere nkesa ndị ọzọ, ọ naghị enweta ọkwa sudoers ozugbo. Ị ga-enwerịrị ike ịnweta ya mgbọrọgwụ paswọọdụ iji iwu su ma ọ bụ gaa na nkuzi nkuzi anyị Otu esi etinye onye ọrụ na Sudoers na Debian.

Wụnye ndabere maka nwụnye

Iji wụnye Golang, ị ga-achọ ijide n'aka na etinyere ngwugwu ndị a. Gbaa iwu a ka ị nyochaa ma ọ bụ wụnye ngwugwu:

sudo apt install wget software-properties-common apt-transport-https -y

Advertisement


Wụnye Golang

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

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

Rịba ama, n'oge ntuziaka a, 1.7 Version bụ ọ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:

sudo tar -zxvf go1.17.linux-amd64.tar.gz -C /usr/local/

Mara, dochie aga1.17.linux-amd64.tar.gz na wget na tar iwu na ụdị dị ugbu a sitere na ibe nbudata.

Na-esote, ịkwesịrị ịhazi ya ${PATH} mgbanwe gburugburu ebe obibi ịgụnye akwụkwọ ndekọ aha Go's bin /usr/loca/go/bin.

Ị nwere ike ime nke a site na iji echo iwu dị ka ndị a:

Nhọrọ 1. Bunye nrụnye n'obosara sistemu wee buo ya gburugburu na nnọkọ nbanye gị ugbu a:

echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee /etc/profile.d/go.sh
source /etc/profile.d/go.sh

Nhọrọ 2. Wụnye profaịlụ akọwapụtara ma tinye gburugburu na nnọkọ nbanye gị ugbu a:

echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee -a $HOME/.profile source
source $HOME/.profile

Na-esote, nyochaa nrụnye aga na arụrụ ugbu a site na iji iwu a:

go version

Ihe atụ mmepụta:

go version go1.17 linux/amd64

Mepụta ngwa ule

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 a (.go) faịlụ. Ụ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 (Golang) nke ọma site na ịwụnye isi iyi 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ọ

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