Download and setup
curl -O https://storage.googleapis.com/golang/go1.9.1.linux-amd64.tar.gz
tar -xvf go1.9.1.linux-amd64.tar.gz
sudo mv go /usr/local
Setting path
vim ~./profile
#add as last line
export PATH=$PATH:/usr/local/go/bin
#add as last line
export PATH=$PATH:/usr/local/go/bin
Init
source ~/.profile
Test
mkdir $HOME/gowork
mkdir -p $HOME/gowork/src/hello
mkdir -p $HOME/gowork/src/hello
Set gopath
export GOPATH=$HOME/gowork
Write hello.go
Note: save under $HOME/gowork/src/hello
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}
Compile and run
use run, compile or install
from source folder run
go run hello.go
#or
go build hello.go
./hello
cd $GOPATH
go install hello
#run
$GOPATH/bin/hello
go run hello.go
#or
go build hello.go
./hello
cd $GOPATH
go install hello
#run
$GOPATH/bin/hello
Install and config Go extension on VSCode
This extension uses a set of Go tools to provide the various rich features. These tools are installed in your GOPATH by defaultsettings
"go.gopath": "/home/user/gowork"
No comments:
Post a Comment