linux to build go environment installation configuration explanation
- 2021-01-19 22:35:31
- OfStack
Setting up an go environment under linux is simple:
1. Download go1.2.1.linux-386.tar.gz, there are similar packages all over the Internet, and put them in 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 root user, unzip root, unzip and install, 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 extra go directory in 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 has been installed and you can now exit the root user
test.go = test.go = test.go = test.go = test.go = 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 desired results were obtained.
There is a problem, we perform go run test. go try:
taogeqq@taogeqq-virtual-machine:~/myspace$ go run test.go
The program" go Not yet installed. You can install it using the following command:
sudo apt-get install golang-go
taogeqq@taogeqq-virtual-machine:~/myspace$
So, you can use
sudo apt-get install golang-go
1 piece installation, as we talked about before
apt-get
The powerful.
Now that we have it installed, we can ignore it for now
sudo apt-get install golang-go
go run test go go go run test go Add the path to PATH and you'll get OK 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$
Where /home/taogeqq is the home directory of taogeqq.
linux is fun to play with, NM's Windows registry, I'm really sick of it.
conclusion