Go Setup on Linux

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome in this video I will show you how to set up an environment to develop programs using the go programming language on a Linux box I'm using Ubuntu 1604 which is the most recent version of Ubuntu available at this time but the setup step that I'm going to use should be pretty similar in any other Linux distributions out there installing go is not a complex task but there are some expectations and standards that should be used in order to make it easier for you down the road and we're going to talk about that installing go requires two main steps so we first download and install the go tools which are the binaries that we use to compile and run our programs and in addition to that you also need to set up a workspace which is pretty much a directory where you can have all of your programs residing so let's get started I'm going to log in here so this is pretty much a standard Ubuntu desktop installation nothing has been done after the installation other than installing the updates so first step we're going to open Firefox and download the go tools so we go to this page here golang.org slash DL and we have the go tools available for different platforms in our case we're going to use the Linux one the current version at the time of this video is 1.6.2 you may see a newer version when you're installing yours and this is for the Linux on the amd64 platform so just click and shortly here we have the save file so saving that file to the Downloads directory that's it or down loading and the open not a terminal here okay just come true and now if you go to the Downloads directory in the list we have the file that we have just downloaded and installing the go tools is as simple as entering this file into a location you can enter in any location and setup environment variable to point go there or the easiest route is you own TARDIS to a slash user slash local directory and go will automatically look for the tools in that wreck so you don't need any extra steps that's what we're gonna do we need to use sudo because the slash user slash local directories on by root so without sudo we won't have the permission to do it even then the command to ant are this file and - see to point it to the slash user slash local directory where we wanted to on tar and then we do that just wait for everything to be there that's it so if we move now to change location to slash local slash user slash local slash go you can see that all of the files have been cantar here and then the bin directory we have the main tools that we're going to be using to compile our programs so that's good going back to the home directory second step is to create the workspace so again the workspace is basically a directory where you are going to have all of your programs when you're developing them and also some additional tools or libraries that you can download and use as dependency on your program so it's by convention usually you have a directory called go in your home directory so that's what we're gonna do and that's it so now I have the goal directory here and in order to make this work we need to go inside to change to the goal directory and in here we need to create three additional directories the source directory for the source files the pkg directory for compiled packages or libraries in the bin directory for compiled programs that's ready and as a final step we need to set up some environment variables to tell go where you can find those directories in order to do that we're going to edit the dot profile file that file gets executed every time you log in into the system so ensure that the variables will be set every time we log into the system they're ready to use so we're gonna edit that file we're going to export a variable called go path and that's the workspace so we set that your home directory slash go and then we also set the path to the current path plus the slash user slash local slash go slash bin so we can run all of the go tools we don't have to type the full path all the time and also add the go path slash bin so we can run our own programs or any other tools that we download into the workspace without having to type the full path to test this we just source the dot profile file into the local shell and if everything is correct we can type go and it will show you the in the variables that go is using so the go path is correctly set to the home directory slash bow so in this case home record which is my directory but in yours should be your home directory slash Co and just reassure that everything is correct let's create a small hello world program we can go to the go path slash source and in here we can create another director again this is also a convention so you have the github.com slash your github account in this case is gonna create as Ricardo and this is your local directory to develop your own programs and due to this naming convention if you download any other packages that will also be fully qualified with github and dot-com for example and the account of the person that created that package that those packages will not conflict and then my personal space here I will create another directory for the hello world program called hello-o there and let's edit our hello Co program just to test this is small program so create package main we import the fund package this is part of the standard library and contain some widely used functions like functions to print text into the screen and then we create a fund name and in that func main we just asked to print line and that line will be hello world that's it you can save it there is our hello file to test it we can just type go run in the name of the file and it will compile and execute that file so we can see that it's working and if we go install you we will install this program into the big directory on the workspace so if you go to dollar go path slash bin the hello program compile is there and even when we're not in that directory just type hello now sis that's added to the path it will execute the program which means that the go tools in the environment in the workspace are correctly set and your environment is ready to use to develop your go programs that's it for now thanks for watching and stay tuned this channel for other videos on the go programming languages and other cool IT stuff thank you you
Info
Channel: Ricardo Gerardi
Views: 11,738
Rating: undefined out of 5
Keywords: golang linux programming, golang, Linux, go
Id: R-cA6J3IniI
Channel Id: undefined
Length: 9min 46sec (586 seconds)
Published: Wed Jul 06 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.