Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
How to put latest version of golang on EC2 server
First get into your EC2 server
If you have already run
$ sudo apt-get install golang
and you have
$ go version
go version go1.2.1 linux/amd64
or something else out of date, you need to remove it before anything
$ rm -r go
$ sudo apt-get remove golang
OK now you can get the latest version you want from here:
and run
$ wget
now $ ls and you should see the tarball there:
ubuntu@ip-0-0-0-0:~$ ls
Lets untarball it into this directory /usr/local (you need to sudo it) like so:
$ sudo tar -C /usr/local -xzf go1.4.2.linux-amd64.tar.gz
Now cd into /usr/local
$ cd /usr/local
now your command should show you are in there like below...and then ls to see what you have in there:
ubuntu@ip-0-0-0-0:/usr/local$ ls
bin etc games go include lib man sbin share src
Above are the untarred files. (yay)
Now we have to vim into our file to add this: export PATH=$PATH:/usr/local/go/bin to the end of the: /etc/profile file.
$ sudo vim /etc/profile
Now you need to get into 'insert' mode by inputting the letter i
You will see on the bottom it now says INSERT. Congratulations, you are in insert mode.
Now arrow down to the bottom of the page and add
export PATH=$PATH:/usr/local/go/bin
Great, now save what you did by FIRST hitting esc THEN inputting :w
Now get out by inputting :q
You should be back on your command line. Now again paste the same line: export PATH=$PATH:/usr/local/go/bin
Like so in your command line while still inside /usr/local
ubuntu@ip-0-0-0-0:/usr/local$ export PATH=$PATH:/usr/local/go/bin
Great Now lets see that we have the correct version:
$ go version
go version go1.4.2 linux/amd64
Allll riggghhttt!
Lets make a simple program to make sure go will run it correctly:
vim hello.go will create a file and put you in it to edit it.
$ vim hello.go
Again use the vim commands
i to insert
now paste in:
package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
esc to get out
:w to save
:q to get back to command line
If you want to get out without saving use this :q!
Now you are back in your command line. Lets see if the program runs right.
$ go run hello.go
If you see
hello, world
WOOOOOOT. You did it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment