Home > Backend Development > Golang > Install golang environment on ubuntu

Install golang environment on ubuntu

WBOY
Release: 2023-05-10 21:16:35
Original
1451 people have browsed it

Ubuntu is a widely used Linux operating system with a large user base. At the same time, golang is also one of the very popular programming languages ​​​​in recent years. If you want to use golang in Ubuntu system, you need to install golang environment. In this article, we will introduce you how to install golang in Ubuntu system.

  1. Prerequisites

Before you start installing golang, you need to ensure that the following software has been installed on the Ubuntu system:

  • curl
  • git

If these two software are not installed in your Ubuntu system, you can install them through the terminal command:

sudo apt-get update
sudo apt-get install curl git
Copy after login
  1. Download golang

Before installing golang, you need to download the golang binary first.

You can download the corresponding version of the binary file through golang's official website (http://golang.org/dl/). In the download page, you can choose the installation package suitable for your system. Usually we choose to download the latest version of the installation package.

After downloading, you can open the terminal and switch to the directory where the downloaded binary file is stored. For example, if your download folder is located in the home directory, you can use the following command to switch:

cd ~/Downloads
Copy after login
  1. Install golang

There are two ways to install golang in the Ubuntu system Method: Install using binaries and use PPA.

3.1 Install using binary files

Install golang through the following steps:

  1. Unzip the downloaded golang compressed package. You can use the following command to decompress:
sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
Copy after login

Note: Please pay attention to replace $VERSION, $OS and $ARCH with the golang version you downloaded, the operating system of your Ubuntu system and the type of your CPU .

  1. Set environment variables.

Before using golang, you need to set two environment variables, GOPATH and PATH.

GOPATH refers to the directory where you will store golang code, and PATH needs to contain the bin folder of the golang installation directory.

You can use the following command to set environment variables:

echo 'export GOPATH="$HOME/go"' >> ~/.bashrc
echo 'export PATH="/usr/local/go/bin:$GOPATH/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Copy after login

After setting the environment variables, you can start using golang.

3.2 Installation using PPA

PPA (Personal Package Archive) makes it easier to install software in Ubuntu systems. You can add golang PPA through the following command:

sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt-get update
sudo apt-get install golang-go
Copy after login

After the installation is completed, you can use the following command to check whether golang is successfully installed:

go version
Copy after login

If the version number of golang is returned, it means You have successfully installed golang.

Conclusion

In this article, we introduce you to two methods of installing golang environment in Ubuntu system. You can choose the method that suits you according to your situation. After the installation is complete, you can start using golang.

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

source:php.cn
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