There are usually several ways to install Go language (Golang) on Ubuntu, and here are some common installation steps:
Method 1: Use the package manager to install
Update package list:
sudo apt update
Install Go:
sudo apt install golang-go
Verify installation:
go version
Method 2: Compile and install from source code
Installation dependencies:
sudo apt install -y git mercurial
Download Go source code:
git clone /go
Compile and install Go:
cd go/src./
Set environment variables:
Add the following to your~/.bashrc
or~/.profile
In the file:
export GOROOT=/home/yourusername/go export PATH=$PATH:$GOROOT/bin
replaceyourusername
For your username and reload the configuration file:
source ~/.bashrc
Verify installation:
go version
Method 3: Use version management tools to install (such as gvm)
Install GVM:
bash < <(curl -s -S -L /moovweb/gvm/master/binscripts/gvm-installer)
Install Go:
gvm install go1.18.3 # Replace with the version you needgvm use go1.18.3
Verify installation:
go version
Things to note
- After the installation is complete, make sure
GOPATH
Set environment variables to your system path, which is the path to the Go language workspace. - You can use
go get
Command to install third-party libraries.
Please choose the appropriate installation method according to your Ubuntu version and personal preferences. If you need to install a specific version of Go, you may need to look for a specific installation command for that version.
To set up a Go proxy in Ubuntu system, you can follow these steps:
Enable Go Modules:
For Go 1.13 and above, you need to enable Go Modules feature. The environment variable can be set through the following commandGO111MODULE
:
go env -w GO111MODULE=on
Configure GOPROXY environment variables:
You can choose to use a different Go proxy service. The following are some commonly used Go proxy services and their configuration methods:
Official *(recommend):
go env -w GOPROXY=,direct
This will set up a Go proxy as the official Go proxy service, which provides global CDN acceleration and supports official sumdb.
Alibaba Cloud *:
go env -w GOPROXY=/goproxy/,direct
The Go proxy service provided by Alibaba Cloud is suitable for mainland China and can provide faster download speeds.
Qiniu Cloud *:
go env -w GOPROXY=,direct
The Go proxy service provided by Qiniu Cloud is also suitable for mainland China, providing the characteristics of fast download and no bandwidth restrictions.
Make the configuration effective for a long time:
If you want these settings to work for a long time, you can add the above commands to your shell configuration file, e.g.~/.bashrc
or~/.profile
:
echo "export GO111MODULE=on" >> ~/.bashrc echo "export GOPROXY=,direct" >> ~/.bashrc source ~/.bashrc
Please select the correct configuration file according to the shell type you are using (such as bash, zsh, etc.).
Verify configuration:
After the setup is complete, you can verify it by following the commandGOPROXY
Is it set correctly:
go env | grep GOPROXY
If the output shows the proxy address you set, the configuration will be successful.
Through the above steps, you can successfully set up a Go proxy in the Ubuntu system, thereby speeding up the download of Go dependency packages.
This is the article about installing golang and setting goproxy in ubuntu. For more related content on installing golang in ubuntu, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!