Configure Golang Development Environment on Ubuntu 14.04
Golang is a programming language launched by Google 10 years ago. Currently, the latest version 1.4 has officially started to support Android development, and Golang is also a Docker development language.
This document describes how to set up the Golang Language Development Environment on Ubuntu 14.04.1 64bit.
Install Golang
Download the latest stable version from the official website:
wget https://storage.googleapis.com/golang/go1.4.linux-amd64.tar.gzsudo tar -xzf go1.4.linux-amd64.tar.gz -C /usr/local
Configure environment variables and usesudo vim /etc/profile
And add the following content:
GOPATH="/YOUR/USER/HOME/go"GOROOT="/usr/local/go"PATH=$GOROOT/bin:$PATH
GOPATH is the Development Directory of Golang. According to the instructions in the official documentation, a fixed directory structure is required:
GOPATH=/home/user/gocode/home/user/gocode/ src/ foo/ bar/ (go code in package bar) x.go quux/ (go code in package main) y.go bin/ quux (installed command) pkg/ linux_amd64/ foo/ bar.a (installed package object)
GOROOT is the installation directory of Golang, andbin
Add the PATH environment variable to the subdirectory.
Install Sublime
Install Sublime Text 3
Sublime Text is a beautiful editor with powerful plug-in community support and can be configured as a lightweight IDE in various languages. Refer to askUbuntu.com's article throughapt-get
Install sublime-text3:
sudo add-apt-repository ppa:webupd8team/sublime-text-3sudo apt-get updatesudo apt-get install sublime-text-installer
After installation, you can runsubl
Start Sublime Text 3
Install Package Control
Official installation documentation
Install GoSublime
After opening Sublime TextCtrl + Shift + P
Open the Package Control plug-in and enterinstall
And then searchGosublime
And install.
Set Font
Start Sublime and clickPreferences -> Settings-User
, Add the following two sentences in curly braces and save the modified fontCourier New
Same Width Font:
"font_face": "Courier New","font_size": 10,
Note the font setting of Sublime Text 3. refer to the answer provided by StackOverflow.
Install LiteIDE
To facilitate debugging or get used to IDE, LiteIDE is Golang's integrated development environment, but requires the dependent libraries of Qt 4.8. You can select Source code compilation or directly download the compiled version from sourceforge.net.
Environment Test
Confirm the deployment of the development environment by using a simple example.src
Create a project directory in the Directory recommended by objective go and create a new source file hello_world.go. Enter the following content:
package mainimport "fmt"func main(){ fmt.Println("hello world!")}
The package management is a bit like JAVA:
- Use
package
Keyword defines the package name.
- Use
import
Introductionfmt
Package.
- Use
func
Keyword-defined functions.
- The entry function of the program is
main
Function.
- Call
fmt
InPrintln
Function print output.
Open the file in Sublime Text and useCtrl + B
Start the Console and entergo help
Let's take a look at the parameter description of the go compiler, and then enter the following command to run this example in interpreted mode:
go run hello_world.go
Now, Environment configuration is complete.
Getting started with Linux-installing Go in Linux
Install Go Language Pack in Ubuntu
Go language programming (HD) full-version ebook
Go language and beauty-surpassing "Hello World"
Why do I like the Go language?
Implementation of the Go language memory distributor