Home > Operation and Maintenance > Linux Operation and Maintenance > How to install and configure golang on linux

How to install and configure golang on linux

王林
Release: 2023-05-14 21:37:19
forward
1403 people have browsed it

Download and install Golang:

First, we need to download and install Golang on the Linux system, the steps are as follows:

  1. In the terminal, obtain the official Golang installation package through the following command:


    wget https://golang.org/dl/
    
    Copy after login


  2. Unzip To install the package, you can use the following command:


    tar -zxvf go1.*.linux-amd64.tar.gz
    
    Copy after login


  3. ##Move the decompressed directory to /usr/local Directory:


    mv go /usr/local
    
    Copy after login


  4. Use the export command to configure environment variables:


    export GOROOT=/usr/local/go 
    export GOPATH=$HOME/go 
    export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
    
    Copy after login


After completing the above operations, our Golang has been installed successfully.

Configure alternate libraries:

Golang is an open source programming language that has a large amount of community support, and many commonly used libraries and tools can be found in GitHub. In order to facilitate developers to develop quickly, we can download these libraries to the local computer.

Steps:

  1. Enter the following command in the terminal to obtain the backup library:


    git clone git://github.com/ThinkiumGroup/go-common.git
    
    Copy after login


  2. Go to the library folder via the cd command:


    cd go-common
    
    Copy after login


  3. Execute the following command to download all required libraries:


    go get ./...
    
    Copy after login


  4. ##After completing the above operations, the backup library All have been downloaded and can be called directly when developing applications.

Implement quick start:

In order to facilitate developers to get started quickly, we can create a simple hello world program.

Steps:

    Enter the following command in the terminal to create a file named hello.go:
  1. vim hello.go
    
    Copy after login


  2. Copy the following code into the hello.go file:
  3. package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Hello, World!")
    }
    
    Copy after login


  4. Save the file and exit vim.
  5. Run the following commands to build and run the program:
  6. go build hello.go 
    ./hello
    
    Copy after login


    The output is :Hello, World!

The above is the detailed content of How to install and configure golang on linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template