Explanation of installation and configuration of building go environment under linux

Explanation of installation and configuration of building go environment under linux

It is very simple to build a go environment under Linux:

1. Download go1.2.1.linux-386.tar.gz, there are similar packages everywhere on the Internet, and put it in the linux directory.

taogeqq@taogeqq-virtual-machine:~/myspace$ ls
a.out go1.2.1.linux-386.tar.gz test.cpp test.go
taogeqq@taogeqq-virtual-machine:~/myspace$

2. Switch to the root user, unzip it under root, and install it after unzipping. What a green software:

 root@taogeqq-virtual-machine:/home/taogeqq/myspace# tar zxvf go1.2.1.linux-386.tar.gz -C /usr/local/

As you can see, there is an additional go directory under the directory:

root@taogeqq-virtual-machine:/home/taogeqq/myspace# ls /usr/local
bin etc games go include lib man sbin share src
root@taogeqq-virtual-machine:/home/taogeqq/myspace#

At this point, the go environment is installed and you can now exit the root user

3. Write a test.go file and test:

taogeqq@taogeqq-virtual-machine:~/myspace$ ls
a.out go1.2.1.linux-386.tar.gz test.cpp test.go
taogeqq@taogeqq-virtual-machine:~/myspace$ 
taogeqq@taogeqq-virtual-machine:~/myspace$ cat test.go
package main
import "fmt"
func main(){
  fmt.Println("hello world")
  fmt.Println("This is my first Go code")
}
taogeqq@taogeqq-virtual-machine:~/myspace$ 
taogeqq@taogeqq-virtual-machine:~/myspace$ /usr/local/go/bin/go run test.go
hello world
This is my first Go code
taogeqq@taogeqq-virtual-machine:~/myspace$

The expected results were obtained.

There is a problem. Let's try it by executing go run test.go:

taogeqq@taogeqq-virtual-machine:~/myspace$ go run test.go
The program 'go' is not installed. You can install it using the following command:
sudo apt-get install golang-go
taogeqq@taogeqq-virtual-machine:~/myspace$

It can be seen that you can use sudo apt-get install golang-go to install it in one go. We have also mentioned the power of apt-get before.

Now that we have installed it, we can ignore sudo apt-get install golang-go . What should we do if we want to execute go run test.go ? It's very simple, just add this path to PATH, as follows:

taogeqq@taogeqq-virtual-machine:~/myspace$ echo $PATH           
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
taogeqq@taogeqq-virtual-machine:~/myspace$ 
taogeqq@taogeqq-virtual-machine:~/myspace$ vim /home/taogeqq/.bash_profile
taogeqq@taogeqq-virtual-machine:~/myspace$ 
taogeqq@taogeqq-virtual-machine:~/myspace$ cat /home/taogeqq/.bash_profile
export PATH=$PATH:/usr/local/go/bin/
taogeqq@taogeqq-virtual-machine:~/myspace$ 
taogeqq@taogeqq-virtual-machine:~/myspace$ source /home/taogeqq/.bash_profile
taogeqq@taogeqq-virtual-machine:~/myspace$ 
taogeqq@taogeqq-virtual-machine:~/myspace$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/go/bin/
taogeqq@taogeqq-virtual-machine:~/myspace$ 
taogeqq@taogeqq-virtual-machine:~/myspace$ go run test.go
hello world
This is my first Go code
taogeqq@taogeqq-virtual-machine:~/myspace$

Among them, /home/taogeqq is the home directory of taogeqq.

It's fun to play with things under Linux, but NM's Windows registry really annoys me.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Goland installation and activation tutorial (window, linux installation)
  • Detailed tutorial on installing Go language in Linux system
  • How to call Linux commands using Golang
  • How to get the CPU usage of system processes through go language under Linux
  • Get access/creation/modification time of files on linux using golang
  • Setting up the Go language development environment under Linux system

<<:  Application scenarios and design methods of MySQL table and database sharding

>>:  vue2.x configuration from vue.config.js to project optimization

Recommend

mysql-5.7.28 installation tutorial in Linux

1. Download the Linux version from the official w...

A brief talk about JavaScript Sandbox

Preface: Speaking of sandboxes, our minds may ref...

Nginx implements https website configuration code example

https base port 443. It is used for something cal...

Hyperlink icon specifications: improve article readability

1. What is the hyperlink icon specification ?<...

How to set up remote access to a server by specifying an IP address in Windows

We have many servers that are often interfered wi...

iview implements dynamic form and custom verification time period overlap

Dynamically adding form items iview's dynamic...

vue-cli introduction and installation

Table of contents 1. Introduction 2. Introduction...

MySQL subqueries and grouped queries

Table of contents Overview Subqueries Subquery Cl...

Detailed steps to install the specified version of docker (1.12.6) using rpm

1. Reasons If the system is Centos7.3, the Docker...

MySQL learning database operation DML detailed explanation for beginners

Table of contents 1. Insert statement 1.1 Insert ...