I'm looking for the correct way to install golang 1.9 into my laptop that is running Ubuntu 16.04.
Many thanks
I'm looking for the correct way to install golang 1.9 into my laptop that is running Ubuntu 16.04.
Many thanks
Nothing better than to follow the source of the project Ubuntu install for Go - GitHub
just replace 1.8 with 1.9
Download golang 1.9 tar from official site.
Then extract it into /usr/local
, creating a Go tree in /usr/local/go
as follows:
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
After extracting add the following lines to your $HOME/.profile
.
# Set GOROOT
export GOROOT=/usr/local/go
export PATH=$GOROOT/bin:$PATH
NOTE: Notice that I have added $GOROOT/bin
before PATH
to override default golang version getting invoked. For setting GOPATH
and GOBIN
follow instructions from official site of golang.
Sorry this was to long to use the comment section. This is a follow-up to my original question. Thanks to the people that provided me with answers which helped point me in the correct direction.
Just a bit of background. I have an old HP notebook which had Windows installed. Went to upgrade to windows 10 but Microsoft informed me that I had an illegal version of windows installed and that I had to purchase windows 10. I did not like that idea for a couple of reasons. First, the version of Windows installed in my computer was installed professionally by a certified Microsoft repair facility. Second, while I don’t mind paying for good software I do not want to have to purchase it again, again and again. So as a noob with a hobby level interest I ended up installing Ubuntu 16.04 then installed a LAMP stack so I could begin to learn to code. My old notebook just did not have the specs for it to run at a decent pace and while I’m not in a hurry it was ridiculously slow. So I thought about a few options. One, purchase a new laptop (I was kind of lusting after a new Dell 13” developers version) but I did not want to drop the coin at this time. Two, look for other options to use my notebook. I chose to go with a fresh installation of Lububtu/MATE hoping that it would be light enough to run in the notebook at a decent pace. I really like the lubuntu installation and my notebook seems to like it to. I am attempting to learn my way around the Linux ecosystem while learning how to write code. I am interested in eventually creating a website which peaked my interest in learning golang. I may be wrong but from what I have read it appears to be a great language for both the front and back ends of a web site. I thought that if I could learn one language that could accomplish the goal of creating a website that it would be better than attempting to learn several different languages then blending them to create a website. That prompted my initial question regarding the installation of golang. Since then I have studied several different sources of information (golang.org, multiple web searches, You Tube videos and signed up for a Udemy class) regarding golang and its installation. The following is the notes I took and terminal commands used to successfully install golang into my Lubuntu OS and (go get) repos from github. I hope this helps someone. NOTE: It is written from the total noob perspective and there may be some errors in it. It appears that there are multiple different ways to accomplish the same objective. Good luck.
GOLANG installation into your Ubuntu 16.04 PC WITHOUT provisions for github imported packages.
Step 1: Download GO a- Go to https://golang.org/dl/ b- Select Linux and download go 1.9.1
Step 2: Extract GO and install. Go to the downloaded file, open in the terminal and extract GO from that tar.gz file. tar -xzf go1.9.1.linux-amd64.tar.gz
Step 3: Move GO to the installation location. sudo mv go /usr/local/go
Step 4: Change the owner to root and alter permissions. NOTE: There appears to be multiple options for this step. I’m not sure that it is necessary if you are NOT going to use this in a production environment. cd /usr/local sudo chown root:root /usr/local/go sudo chmod 755 go cd
Step 5: Create your workspace folder.
I will be calling my workspace folder go workspace but name your workspace whatever you want.
NOTE: bin/pkg/src folders are stored within folder.
bin= Folder from where the compiled code will be executed from.
pkg= Folder where your library and or third party packages will be imported / stored.
src= Folder where you will write your GO code
sudo mkdir <your workspace folder name here>{,/bin,/pkg,/src}
Step 6: Edit the System Environment Variables via your choice of text editor (gedit/nano/vim etc)
sudo nano /etc/profile
Then add:
export PATH=$PATH:/usr/local/go/bin
Save and exit.
Open:
nano.profile
At the bottom of the profile add:
export GOPATH=$HOME/<your workspace folder name here>
On the next line add:
export PATH=$HOME/<your workspace folder mane here>/bin:$PATH
Save, exit and restart your computer. On the command line type:
reboot
Upon restart GO should be installed and ready for use.
Step 7: Confirm your GO installation. Open terminal and type:
go version
It should return as go1.9.1 linux/amd64
Next command line input:
go env
The GO env should populate displaying (GOPATH, GOROOT and etc)
---- Optional Installation ----
GOLANG installation into your Ubuntu 16.04 PC WITH provisions for github imported packages.
All the above steps apply with the addition of the github provision. The terminal commands are condensed but the github provisions will be explained in more detail.
Download GO. https://golang.org/dl/
Open the Download file in the terminal and extract. tar -xzf go1.9.1.linux-amd64.tar.gz
Move GO to the installation location. sudo mv go /usr/local/go
Change the owner to root and alter permissions. cd /usr/local sudo chown root:root /usr/local/go sudo chmod 755 go
Change directory and create your workspace folder: sudo mkdir {,/bin,/pkg,/src}
Change directory to src. Then Within the src folder create a new folder named github.com cd src sudo mkdir github.com
Change directory to github.com. Within the github.com folder create a new folder using your github.com username. cd github.com sudo mkdir
Within your github.com user name folder you can create one or more folders for your go code project / repos.
Edit the System Environment Variables sudo nano /etc/profile
Then at the bottom add: export PATH=$PATH:/usr/local/go/bin
Save and exit.
open: sudo nano.profile
At the bottom of the profile add: export GOPATH=$HOME/
On the next line of the profile add: export PATH=$HOME//bin:$PATH
Save, exit and restart your computer. On the command line type: reboot
NOTE: Flow chart of your GO workspace folder(s) 1. Your go workspace (gows) folder a. bin folder (inside your workspace (gows) folder) b. pkg folder (inside your workspace (gows) folder) c. src folder (inside your workspace (gows) folder) 2. github.com (inside src folder) 3. Your github user name folder (inside your github.com folder) 4. GO project code/git repository folder(s) (inside your github username folder)
The above structure allows for handeling of namespacing and package management. (go get)
GOLANG INSTALLATION TEST: (One option) Terminal command to install golang training code. go get github.com/< a github user name>/
Sorry this was a bit long. I hope this helps someone. Good luck.
I have used this tiny script I made. Not perfect, not working on any linux distro. Gave me a working go installation on ubuntu.
https://gist.github.com/Pherserk/010cf965e8762f1224efc18f4eb510ba
GVM (Go Version Manager)
https://github.com/moovweb/gvm
Allows installing without sudo
and can compile any version for you.
Usage:
# https://github.com/moovweb/gvm/issues/302
sudo apt-get install golang-go
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
. ~/.gvm/scripts/gvm
v=go1.11
gvm install "$v"
gvm use "$v"
go version
Outputs:
go version go1.11 linux/amd64
Then packages work as normal:
go get github.com/github/hub
hub --version
The script automatically adds to your .bashrc
:
[[ -s "/home/ciro/.gvm/scripts/gvm" ]] && source "/home/ciro/.gvm/scripts/gvm"
but I prefer to remove it and add instead:
f="$HOME/.gvm/scripts/gvm"
if [ -f "$f" ]; then
. "$f"
gvm use go1.11 2>&1 >/dev/null
fi
Tested on Ubuntu 18.04, GVM 6ecd46d8b58c18f2a7bd5a1ab604cb57443cd35c.