The impulse to replace the notebook with the Linux Mint system, so share the experience of installing Golang under Linux
Installation
First, you can install the latest version of Go directly from the command line:
Apt Install Golang
Here the main introduction of manual installation process, first to download the latest installation package: Go download
Select the Linux version and after downloading, unzip to/usr/local:
Tar-c/usr/local-xzf go1.10.3.linux-amd64.tar.gz
Configuring Environment variables
Edit the/etc/profile file and add to the end:
export PATH=$PATH:/usr/local/go/bin
After saving, use the command source Etc/profile to take effect.
After you install go, the default is to use $home/go as the working directory, or you can manually specify the directory, set Gopath to define the directory. To configure environment variables for the current user, edit. BASHRC or. Profile, add:
export GOPATH=$HOME/goexport PATH=$PATH:$GOPATH/bin
After the configuration is complete, enter go-version to view the installed version.
$ go
Test
After the configuration, the test can compile the go file normally, first create the HelloWorld package and the corresponding go source file:
$ mkdir -p go/src/helloworld$ cd go/src/helloworld$ touch helloworld.go
Write code to the source file:
package mainimport "fmt"func main() { fmt.Printf("hello, world\n")}
Then start compiling:
$ cd $HOME/go/src/helloworld$ go build
Permissions may appear at this time can ' t load Package:...permission denied
You need to add permissions to the directory:
chmod 755-r $HOME/go
The corresponding executable file is generated after the compilation is passed
$ cd $HOME/go/src/helloworld$ go build$ lshelloworld helloworld.go$ ./helloworldhello, world
Compile through to be able to print normally.