{"id":136,"date":"2021-01-21T20:06:18","date_gmt":"2021-01-21T20:06:18","guid":{"rendered":"https:\/\/kindsonthegenius.com\/go\/?p=136"},"modified":"2021-01-21T20:11:20","modified_gmt":"2021-01-21T20:11:20","slug":"go-programming-setup","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/go\/2021\/01\/21\/go-programming-setup\/","title":{"rendered":"Go Programming &#8211; Setup"},"content":{"rendered":"<p>In this tutorial, we would be able to setup Go and write out first program.<\/p>\n<p><strong>In Windows<\/strong><\/p>\n<p>Download <a href=\"https:\/\/golang.org\/dl\/\" target=\"_blank\" rel=\"noopener\">Go Installer package from here.<\/a> Go ahead to install it depending on your OS. This would be a .msi file. Run the downloaded file.<\/p>\n<p>By default the installer would install Go on your C drive at C:\\Go. This is the default workspace<\/p>\n<p>To check that Go installed correctly, open the command prompt and type the following command<\/p>\n<pre>go version\r\n<\/pre>\n<p>The would display the version of Go installed<\/p>\n<p><strong>In Mac<\/strong><\/p>\n<p>If\u00a0 you are using Mac, then open your terminal and install Go using the following command:<\/p>\n<pre>brew install golang\r\n<\/pre>\n<p>The default install location for Mac is \/usr\/local\/go<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u00a0In Linux<\/strong><\/p>\n<p>Download the and extract the archive into the folder \/usr\/local. So you will have a directory \/usr\/local\/go<\/p>\n<p>Add the \/usr\/local\/go\/bin to the PATH. To do that you need to execute the command:<\/p>\n<pre>export PATH=$PATH:\/usr\/local\/go\/bin\r\n<\/pre>\n<p>The confirm the installation using go version<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Using an IDE<\/strong><\/p>\n<p>For me, I prefer using an IDE. In this case, the IDE for Go is the GoLand IDE developed by JetBrains. You can find it <a href=\"https:\/\/www.jetbrains.com\/go\/download\/#section=windows\" target=\"_blank\" rel=\"noopener\">here<\/a><\/p>\n<p>I think you can get a 30-trial version or a free version if you are student or teacher and want to use it for learning purposes. That is what I did! Once you have installed it, open it. It open the window as shown below:<\/p>\n<figure id=\"attachment_141\" aria-describedby=\"caption-attachment-141\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-141 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.46.44-1024x671.png\" alt=\"GoLand welcome page\" width=\"1024\" height=\"671\" srcset=\"https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.46.44-1024x671.png 1024w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.46.44-300x197.png 300w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.46.44-768x503.png 768w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.46.44-1536x1007.png 1536w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.46.44.png 1736w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-141\" class=\"wp-caption-text\">GoLand welcome page<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>Click on New Project and ensure that Go is selected in the GOROOT field as shown below.<\/p>\n<p>Give the project a name. In this case, the name is awesomeProject2<\/p>\n<figure id=\"attachment_142\" aria-describedby=\"caption-attachment-142\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-142 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.47.40-1024x688.png\" alt=\"GoLand new project\" width=\"1024\" height=\"688\" srcset=\"https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.47.40-1024x688.png 1024w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.47.40-300x202.png 300w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.47.40-768x516.png 768w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.47.40-1536x1032.png 1536w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.47.40.png 1824w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-142\" class=\"wp-caption-text\">GoLand new project<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>Click on Create to create the Project. The new project window is opened as shown below:<\/p>\n<figure id=\"attachment_143\" aria-describedby=\"caption-attachment-143\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-143 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.53.28-1024x703.png\" alt=\"New project in Go\" width=\"1024\" height=\"703\" srcset=\"https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.53.28-1024x703.png 1024w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.53.28-300x206.png 300w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.53.28-768x527.png 768w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.53.28-1536x1054.png 1536w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-20.53.28-2048x1405.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-143\" class=\"wp-caption-text\">New project in Go<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>Right-click on the project name and choose New &gt; Go File. I name it firstProg. The file extension is .go.<\/p>\n<p>Then enter the following code:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">package<\/span> main\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">import<\/span> <span style=\"background-color: #fff0f0;\">\"fmt\"<\/span>\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">func<\/span> main() {\r\n\tfmt.Println(<span style=\"background-color: #fff0f0;\">\"Welcome to Go!\"<\/span>)\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Next, right-click on the program and Choose &#8220;Run go build firstProg.go&#8221;. The program runs and displays the result in the output windows as shown below, circled in red:<\/p>\n<figure id=\"attachment_144\" aria-describedby=\"caption-attachment-144\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-144 size-large\" src=\"https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-21.02.12-1024x692.png\" alt=\"Running a Go program in GoLand IDE\" width=\"1024\" height=\"692\" srcset=\"https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-21.02.12-1024x692.png 1024w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-21.02.12-300x203.png 300w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-21.02.12-768x519.png 768w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-21.02.12-1536x1038.png 1536w, https:\/\/www.kindsonthegenius.com\/go\/wp-content\/uploads\/sites\/3\/2021\/01\/Screenshot-2021-01-21-at-21.02.12-2048x1384.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-144\" class=\"wp-caption-text\">Running a Go program in GoLand IDE<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<h5><strong>Next Steps<\/strong><\/h5>\n<p>Now that you have successfully setup Go programming IDE and run a Go program, let&#8217;s now delve into the Go Programming Tutorial proper!<\/p>\n<p>So on to the next part: Basic Syntax of a Go Program.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we would be able to setup Go and write out first program. In Windows Download Go Installer package from here. Go ahead &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[21,22],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-go-programming","tag-goland","tag-ide"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/comments?post=136"}],"version-history":[{"count":3,"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/posts\/136\/revisions\/145"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/media?parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/categories?post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/go\/wp-json\/wp\/v2\/tags?post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}