Ubuntu Download Goalng-1.9_go

Source: Internet
Author: User
I. Installation

Here to install golang1.9 as an example:
1. First install directly from the command line

sudo apt-get install golang-1.9

2. After downloading, view the go version

catik@catik-aspire-v3-471:~$ Go version
Go version go1.9.2 linux/amd64

As you can see, the version here is go1.9.2 two. Environment configuration

1. View Environment variables:

Catik@catik-aspire-v3-471:~$ go env 
goarch= "AMD64"  
gobin= ""  
goexe= ""  
gohostarch= "AMD64"  
gohostos= "Linux"  
goos= "Linux"  
gopath= "/home/catik/godownload" /" 
gorace=" " 
goroot="/usr/lib/go " 
gotooldir="/usr/lib/go/pkg/tool/linux_amd64 " &NBSP
gccgo= "Gccgo"  
cc= "gcc"  
gogccflags= "-fpic-m64-pthread-fmessage-length=0- Fdebug-prefix-map=/tmp/go-build504408127=/tmp/go-build-gno-record-gcc-switches " 
CXX=" g++ " 
cgo_enabled= "1"  
cgo_cflags= "-g-o2"  
cgo_cppflags= ""  
cgo_cxxflags= "-g-o2"  
cgo_fflags= "-g-o2"  
cgo_ldflags= "-g-o2"  
pkg_config= "Pkg-config

Here are a few of the more critical variables Gopath and Goroot
The Gopath is the default download and install package location for the go get instruction, gets the go package by default, and downloads to the directory indicated by the Gopath.
Goroot is the location of the go installation and the location of the go executable, which means that the system can accurately call the go executable when the go instruction is played on our command line.
Here goroot= "/usr/lib/go"
With the following command
Cd/usr/lib/go
Ls
You can see

catik@catik-aspire-v3-471:/usr/lib/go$ ls
Bin Doc favicon.ico.gz Go pkg src test VERSION

The save in the bin is the go executable file, we can try:

catik@catik-aspire-v3-471:/usr/lib/go/bin$./go version
Go version go1.9.2 linux/amd64

This is the same as we enter go directly on the command line
2. Configure Environment variables
By default, Gopath is not configured, so how do we modify these environment variables?
First of all, we can build a folder in one place according to our own wishes, such as

Mkdir/home/catik/godownload

Then, there are three ways to configure environment variables:

One: The most fundamental way is to modify the/etc/profile file

sudo gedit/etc/profile
* Note that sudo is required here because the documents in the system directory are not allowed to be arbitrarily modified.
Add export gopath=/home/catik/godownload at the end
This method of modification is effective for all users, after modification to restart will be another change in effect

Two: This method can also modify the. profile file under the user directory

For example, this is/home/catik/.profile.
You can change it after you open it through Gedit/home/catik/.profile.
The method of modification is the same as the first one, which is to add the last
Export Gopath=/home/catik/godownload

Third: Temporary effect, only this time effective, when you close terminal, no longer effective

Directly on the command line
Golang of catik@catik-aspire-v3-471:~$ export Gopath=/home/catik/godownload upgrade system

If you have Golang installed on your computer, but not the newest version, upgrade your computer's Golang to the latest edition.
For example, the original installation is go1.6, the latest version for go1.9,
First uninstall the old version of the computer

sudo apt-get remove golang-1.6

Then install the latest version of the

sudo apt-get install golang-1.9

After waiting for installation, I found

Go version

Version is still 1.6, it doesn't work. Reboot the computer, or so, what's the problem?
We follow the Goroot place to see

Catik@catik-aspire-v3-471:cd/usr/lib/go
Catik@catik-aspire-v3-471:ls
Bin Doc favicon.ico.gz Go pkg src test VERSION
Catik@catik-aspire-v3-471:cat VERSION
go1.6

So we can see the original go here or the original executable file, the original uninstall did not unload the files here clean, the executable file here has not changed.
So we copied the 1.9 version of the go file here, by the way, the original went folder is a hard link, the target is the original go-1.6 folder, when we install the go-1.9, both folders exist, where we need to remove go-1.6

sudo rm go-1.6-r

Delete the original link file as well

sudo rm go-r

Build a new Go folder

sudo mkdir go

Copy all the files from the go-1.9 to the past

sudo cp./go-1.9/*./go

View the Go version again

Go version
go-1.9.2

Problem solved smoothly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.