Home  >  Article  >  Backend Development  >  linux ubuntu install golang

linux ubuntu install golang

PHPz
PHPzOriginal
2023-05-14 17:16:38597browse

As an open source operating system, Linux system is very popular among developers. Golang is hailed as one of the mainstream programming languages ​​​​in the future and has gradually become one of the preferred languages ​​​​for many developers. In this article, we will introduce how to install Golang on Linux Ubuntu system.

1. Prerequisites

Before installing Golang, you need to ensure that curl and git have been installed on your Ubuntu operating system. If you haven't installed these packages yet, use the following commands to install them.

sudo apt update && sudo apt upgrade
sudo apt install curl git

2. Download Golang

Before installing Golang, you need to download the release version of Golang. Whether downloading on the official website or GitHub, here we choose to download on the official website.

Download link from Golang official website: https://golang.org/dl/ Find the latest version of Golang and copy the link address.

Use the following command to download Golang to the Ubuntu system. The link address is the link address on the official website. Just change the corresponding version number to the version you need.

sudo curl -O https://golang.org/dl/go1.17.1.linux-amd64.tar.gz

3. Install Golang

Once you have Once you download the Golang distribution, you can unzip it and move it to the appropriate directory so you can set it as a global variable and use it in the terminal.

First, you need to extract the downloaded file to the /usr/local directory. The following command will unzip the file and rename it to go.

sudo tar -xf go1.17.1.linux-amd64.tar.gz -C /usr/local/
sudo mv /usr/local/go /usr/local/go1.17.1

Add Golang to the global environment variables with the following command to use it from the command line.

sudo nano /etc/environment

In the opened file, add the following lines to the end:

PATH="/usr/local/go1.17.1/bin: $PATH"

Save changes and exit file.

Let the changes just take effect.

source /etc/environment

Run the following command to check whether Golang has been successfully installed and set as a global variable.

go version

There should be a version number similar to the following output:

go version go1.17.1 linux/amd64

4. Conclusion

Congratulations, you have successfully installed Golang in your Linux Ubuntu system. Now you can start developing applications that make your life easier. Read some Golang related documentation and start with a simple "Hello World" program!

This article only introduces how to install Golang into the Ubuntu system and set it as a global variable. If you want to know more about Golang, please consult the relevant documents yourself.

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

Statement:
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
Previous article:golang cannot enter ChinaNext article:golang cannot enter China