Ubuntu installs the Go language runtime environment

  • 2020-05-27 05:51:58
  • OfStack

On the ubuntu forum, I saw a post that grabbed the image data in the web page, so I wanted to try it in GO language. Install a running environment first. The following installation methods have been successfully installed on 32-bit and 64-bit ubuntu12.04, and I have actually run all the commands and programs. If you have any problems, please leave me a message.

1. Install Mercurial

Mercurial is a version control system. You will use this tool to download the source code of Go. It is very convenient to install OK with apt-get under ubuntu.

sudo apt-get install mercurial

2. Download the source code of Go language

This step creates a new go folder in the current directory on the command line and downloads the code files into the go folder, so make sure there are no go folders in the current directory. For example, I'm working directly in the /home directory.

hg clone -u release https://code.google.com/p/go

3. Start installation

cd go/src

This process takes a little bit of time, one key setup, very powerful. When installed, it will prompt the following information,

Installed Go for linux/386 in /home/go
Installed commands in /home/go/bin
*** You need to add /home/go/bin to your PATH.

The bin directory of go should be set to $PATH. This variable is to run the command to search the path. Since I previously selected the /home directory, the bin directory for go after installation is /home/go/bin

4, international practice, the first procedure Hello world!

package main
import "fmt"
func main() {
        fmt.Printf("Hello, world\n")

Save as hello.go and execute

/home/go/bin/go run hello.go

When you see the output Hello world, the environment has been installed successfully.

That's all for this article, I hope you enjoy it.

Related articles: