GOPATH Setup Windows 2021 | Golang Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] all right what is up guys and welcome to Swedish team in this episode were setting up go from the basics we're downloading it and setting a go path to your workspace and getting up and running with the go so to get started you navigate to golang.org and then you simply press download go this tutorial we'll go through how you set it up in windows so for Apple users I would suggest you can use the package manager brew so you simply brew install go however for Windows we will download go via the web page alright now we can simply open the installation file and proceed by accepting the terms and installing it in the default location and then wait for it to proceed alright now we can press finish here and we open up the command prompt here and type in go help and it looks like we have installed go successfully now so let's set up the workspace now with the environment variables correctly so we can type go and to look at all the environment variables that came would go here we can see what we're interested in is basically go routes that's the directory where go is installed and where all the like main packages etc will live however we also got a go path here which is the path to our workspace and this works based path we can can change in order to get the custom workspace half on our desktop for example so let's set up go workspace on our desktop first of all we can create the new folder on our desktop called go workspace so now we need to tell go to point it's go path to this folder this go workspace folder on our desktop so what we can do is to type in env for environment in our search prompt and here we will go into environment variables and here we can see that we have a go path that has been set and it's corresponding to the one we can see in the command prompt so let's go in and edit this one too much the desktop path that we created ago workspace in so that'll just be slash desktop and back slash go workspace that should be it we press ok and we restart the command prompt and now if we run go environment go we should get our updated go path here corresponding to the path of our desktop folder so let's go into our newly created workspace folder and add the necessary folders which go needs in order to kind of organize your code in a specific way so you have a source folder which contains go source files you so have been flat folder which contains the binary executables and you finally have your packages or like the package archive so a workspace in go is a directory on your system where go will look for source code files we can manage like dependency packages and you can also build the distribution binary files so all of these folders will contain these files so for example when you hit the import statement and go you will actually find that go firstly look in the go root path in the SRC folder there but if it can't find any like source package with that name it will secondary to go to your workspace and look for the package there so it's kind of a nice setup I think and this will get us going so let's just try a quick go script in this code so to quickly test that our go custom go workspace is correctly set up I created a small package here called custom text and it exports to variable what is go and who said T I'm also using vias code with the go extension which I can definitely recommend if you're in for a new editor but now we can create package or go script that actually uses this custom package so we create a folder called test and it shows up here we in tests we create go script called tests go in this we define that it should be executable and we also import fmt to in order to print and we also import our custom text so fmt in this case will be imported from the root directory then go will not be able to find this custom text package inside of the root directory and will therefore try to look for it in our custom workspace directory or the NGO path that we just exported and set so let's print out and see if we can look at these variables and we use it like this and one of the variables was I think to send it tea or something like that so just we can just now we can navigate to our command prompt and from our workspace into the source folder and then into the test folder where our test script lives and then we compile and run with the go run command and see if we can get the correct output and it seems to be working and we have successfully now used the custom package according to the new go path variable that we've been setting right that was all for today thank you very much for watching this was Swedish tea coming at you with another video on go past this time I'll be producing a lot of content ahead so please subscribe if you haven't already also drop a comment below I'm really interested in hearing what you guys think about these types of videos and tell me what I can improve on otherwise I'll see you very soon and please stay tuned for more [Music]
Info
Channel: Swedish Tea
Views: 30,359
Rating: undefined out of 5
Keywords: setup golang, golang custom, custom workspace golang, workspace golang, gopath variable golang, golang gopath, golang 2019, learn golang, golang windows, golang windows 10, golang tutorial, golang basics, learn programming go, go programming, go path, learn go, go tutorial, golang download, google go, go, go programming examples, go programming tutorial, go windows, golang environment setup, golang setup environment variables, golang setup windows, go environment
Id: kjr3mOPv8Sk
Channel Id: undefined
Length: 9min 4sec (544 seconds)
Published: Sun Aug 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.