Home >Backend Development >Golang >Install golang environment on ubuntu
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.
Before you start installing golang, you need to ensure that the following software has been installed on the Ubuntu system:
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
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
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:
sudo tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
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 .
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
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
After the installation is completed, you can use the following command to check whether golang is successfully installed:
go version
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!