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

How to install and configure golang on linux

王林
王林forward
2023-05-14 21:37:191230browse

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/
    


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


    tar -zxvf go1.*.linux-amd64.tar.gz
    


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


    mv go /usr/local
    


  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
    


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
    


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


    cd go-common
    


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


    go get ./...
    


  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
    


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


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


    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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete