Difference between revisions of "Golang/Install"

From Ever changing code
Jump to navigation Jump to search
Line 14: Line 14:
= Multiple versions =
= Multiple versions =
You can have multiple versions fo Golang installed in your system. The way to manage the current version in use is to use <code>update-alternatives</code>
You can have multiple versions fo Golang installed in your system. The way to manage the current version in use is to use <code>update-alternatives</code>
Display best options
<source lang="bash">
sudo update-alternatives --display go
go - auto mode
  link best version is /usr/local/go/bin/go
  link currently points to /usr/local/go/bin/go
  link go is /usr/bin/go
/usr/local/go/bin/go - priority 2
</source>


Before
Before
<source lang="bash">
   Selection    Path                  Priority  Status
   Selection    Path                  Priority  Status
  ------------------------------------------------------------
  ------------------------------------------------------------
Line 21: Line 32:
   1            /usr/bin/gccgo-go      5        manual mode
   1            /usr/bin/gccgo-go      5        manual mode
   2            /usr/bin/golang-go    10        manual mode
   2            /usr/bin/golang-go    10        manual mode
 
</source>
Installed manually unzipped GoLang into <tt>/usr/local/go</tt> but was not added to alternatives. Use command below to add it on:
Action: Installed manually unzipped GoLang into <code>/usr/local/go</code> but was not added to alternatives. Use command below to add it on:
sudo update-alternatives --install "/usr/bin/go" "go" "/usr/local/go/bin/go" 2
<source lang="bash">
 
sudo update-alternatives --install "/usr/bin/go" "go" "/usr/local/go/bin/go" 2
</source>
After
After
<syntaxhighlight lang="bash" highlight="6" line>
   Selection    Path                  Priority  Status
   Selection    Path                  Priority  Status
  ------------------------------------------------------------
  ------------------------------------------------------------
Line 31: Line 44:
   1            /usr/bin/gccgo-go      5        manual mode
   1            /usr/bin/gccgo-go      5        manual mode
   2            /usr/bin/golang-go    10        manual mode
   2            /usr/bin/golang-go    10        manual mode
   3            '''/usr/local/go/bin/go  2        manual mode'''
   3            /usr/local/go/bin/go  2        manual mode
 
</syntaxhighlight>
Then run command to change ''go'' binary available in your shell
Then run command to change ''go'' binary available in your shell
sudo update-alternatives --config go  #then select ''3''
<source lang="bash">
 
sudo update-alternatives --config go  #then select ''3''
</source>
When you run  
When you run  
$ go version #the version of ''go'' will be the one from <tt>/usr/local/go</tt> location.
<source lang="bash">
$ go version #the version of ''go'' will be the one from <tt>/usr/local/go</tt> location.
</source>

Revision as of 15:32, 2 June 2018

Ubuntu Install

Ubuntu LTS 16.04

Download from https://golang.org/dl/ and extract it into <coede>/usr/local, creating a Go tree in /usr/local/go

sudo tar -C /usr/local -xzvf go$VERSION.$OS-$ARCH.tar.gz

Add /usr/local/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile (for a system-wide installation) or $HOME/.profile:

sudo update-alternatives --install "/usr/bin/go" "go" "/usr/local/go/bin/go" 2 #adds to the $PATH
export PATH=$PATH:/usr/local/go/bin #optional

Multiple versions

You can have multiple versions fo Golang installed in your system. The way to manage the current version in use is to use update-alternatives

Display best options

sudo update-alternatives --display go
go - auto mode
  link best version is /usr/local/go/bin/go
  link currently points to /usr/local/go/bin/go
  link go is /usr/bin/go
/usr/local/go/bin/go - priority 2

Before

Selection    Path                  Priority   Status
 ------------------------------------------------------------
   0            /usr/bin/golang-go     10        auto mode
   1            /usr/bin/gccgo-go      5         manual mode
   2            /usr/bin/golang-go     10        manual mode

Action: Installed manually unzipped GoLang into /usr/local/go but was not added to alternatives. Use command below to add it on:

sudo update-alternatives --install "/usr/bin/go" "go" "/usr/local/go/bin/go" 2

After

Selection    Path                  Priority   Status
 ------------------------------------------------------------
 * 0            /usr/bin/golang-go     10        auto mode
   1            /usr/bin/gccgo-go      5         manual mode
   2            /usr/bin/golang-go     10        manual mode
   3            /usr/local/go/bin/go   2         manual mode

Then run command to change go binary available in your shell

sudo update-alternatives --config go  #then select ''3''

When you run

$ go version #the version of ''go'' will be the one from <tt>/usr/local/go</tt> location.