+6

[ENG] Golang: Part 1 - Installation and Introduction

Hi everyone, long time no see, I'm Hieu Pham. I'm very fortunate to have had numerous opportunities while working in the development unit, allowing me to become acquainted with many programming languages. In this article, I will introduce Go (Golang), a programming language that is one of the languages you should learn when becoming a DevOps engineer. (I'm currently in the process of learning to become a DevOps engineer)

First of all, we need to install Go. To do this follow the steps below to install Go on a linux OS.

  1. Download Go from this link: https://go.dev/dl/go1.21.3.linux-amd64.tar.gz (version 1.21.3 at this time)
  2. Extract downloaded archive and copy its contents to the /usr/local directory.
tar -C /usr/local -xzf go1.21.3.linux-amd64.tar.gz
  1. Next, we need to make Go accessible globally by running the following command:
export PATH=$PATH:/usr/local/go/bin
  1. Finally, you can check if Go has been installed successfully by running the command:
go version

By following these steps, you'll have Go installed and ready to use on your Linux system.

For others Operating System, you can use this link to install: https://go.dev/doc/install

Introduction

Golang.png Before we proceed to the next part - how to code, I will first explain to you the reasons why Go (Golang) is a programming language that is quite impressive for our community.

Golang has not only been used by big tech companies such as Google, Meta, Netflix, Microsoft, but it is also a robust language, as far as my knowledge goes. So, what are its strengths ?

  • Go is quite simple to learn and easy to read
  • It's seems powerful performance. (Go is a compiled language, making it more performant than interpreted languages like JavaScript, PHP, etc.).
  • Golang is designed for multi-core processors
  • It is supported by Google.
  • Its performance is on par with C/C++, but its syntax is as simple as Python, PHP, ...
  • Go has concurrency

Golang use for:

  • Web development
  • Cloud & Network Services
  • Command-line Interfaces (CLIs)
  • Development Operations & Site Reliability Engineering.

Getting started: "Hello world"

Every complicated thing comes from smallest thing. Every developer needs learn how to code "Hello, world!". It's absolutely simple when you need print "Hello, world!" on your screen. Create a file which has extension .go and then paste belows code block. We need import "fmt" package to your code and able to use I/O functions like Println, as shown in the code snippet below

package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}

After saving, we need to run it by command:

go run hello-world.go

You can also compile it to execute:

go build hello-world.go
./hello-world

image.png

Good job! You've taken a step into the world of Go lang.

Summary

In this article, we have known about basic of Go programing language. To delve deeper into this language, we need to acquire more knowledge about it. In the upcoming articles, I will introduce and delve into the details of its components and how to use Go. Thank you for following along to the end of this article. If you feel that helpful for yourself, please consider leaving a vote for my article. Thank you and see you in the next ones.


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí