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

How to install mysql on centos and set up remote access

1. Download the mysql repo source $ wget http://r...

Summary of using MySQL isolation columns and prefix indexes

Table of contents Isolate Data Columns Prefix Ind...

MySQL master-slave configuration study notes

● I was planning to buy some cloud data to provid...

Understanding of haslaylout and bfc parsing

1. haslayout and bfc are IE-specific and standard ...

Practical method of deleting a row in a MySql table

First, you need to determine which fields or fiel...

HTML+CSS to achieve charging water drop fusion special effects code

Table of contents Preface: accomplish: Summarize:...

Summary of Vue 3 custom directive development

What is a directive? Both Angular and Vue have th...

Detailed explanation of Vue's list rendering

Table of contents 1. v-for: traverse array conten...

Linux Dig command usage

Dig Introduction: Dig is a tool that queries DNS ...

Summary of Docker Data Storage

Before reading this article, I hope you have a ba...