<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Alabo David Briggs</title>
    <description>The latest articles on Forem by Alabo David Briggs (@alabobriggs).</description>
    <link>https://forem.com/alabobriggs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F192498%2Fb731c936-518b-4234-af35-764ca81ad85e.jpg</url>
      <title>Forem: Alabo David Briggs</title>
      <link>https://forem.com/alabobriggs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alabobriggs"/>
    <language>en</language>
    <item>
      <title>Setup Golang Locally on Mac OSX</title>
      <dc:creator>Alabo David Briggs</dc:creator>
      <pubDate>Mon, 16 Mar 2020 12:45:34 +0000</pubDate>
      <link>https://forem.com/alabobriggs/setup-golang-on-mac-osx-for-local-development-35bb</link>
      <guid>https://forem.com/alabobriggs/setup-golang-on-mac-osx-for-local-development-35bb</guid>
      <description>&lt;p&gt;Recently I switch from a linux development environment to OSX and one of the challenges I faced was setting up golang on OSX.&lt;br&gt;
This article will give you a run down on how to download, setup and get your first golang application up and running on osx.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1 - Installing Golang
&lt;/h2&gt;

&lt;p&gt;The first step to using golang is to have it installed on your computer. To confirm if a version of golang is not installed on your system, type in this command in your desired terminal, I use &lt;a href="https://hyper.is/"&gt;hyper&lt;/a&gt; but any will do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;go 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you should see and output that looks like this if you have it installed&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;go is a tool for managing Go source code.

Usage:
&lt;/span&gt;&lt;span class="gp"&gt;        go &amp;lt;command&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;arguments]
&lt;span class="go"&gt;The commands are:

        bug         start a bug report
        build       compile packages and dependencies
        clean       remove object files and cached files
        doc         show documentation for package or symbol
        env         print Go environment information        fix         update packages to use new APIs
        fmt         gofmt (reformat) package sources
        generate    generate Go files by processing sou
rce
        get         add dependencies to current module 
and install them
        install     compile and install packages and de
pendencies
        list        list packages or modules
        mod         module maintenance
        run         compile and run Go program
        test        test packages
        tool        run specified go tool
        version     print Go version
        vet         report likely mistakes in packages

&lt;/span&gt;&lt;span class="gp"&gt;Use "go help &amp;lt;command&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;" for more information about a command.
&lt;/span&gt;&lt;span class="go"&gt;
Additional help topics:

        buildmode   build modes
        c           calling between Go and C
        cache       build and test caching
        environment environment variables
        filetype    file types
        go.mod      the go.mod file
        gopath      GOPATH environment variable
        gopath-get  legacy GOPATH go get
        goproxy     module proxy protocol
        importpath  import path syntax
        modules     modules, module versions, and more
        module-get  module-aware go get
        module-auth module authentication using go.sum
        module-private module configuration for non-public modules
        packages    package lists and patterns
        testflag    testing flags
        testfunc    testing functions

&lt;/span&gt;&lt;span class="gp"&gt;Use "go help &amp;lt;topic&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;" for more information about that topic.
&lt;/span&gt;&lt;span class="go"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you do not get this output visit &lt;a href="https://golang.org/dl/"&gt;golang download page&lt;/a&gt; and follow the steps below to get golang installed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1 -  Click on the link as shown below
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FYmFJ1ml--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xsm44s2g1sm5b4h3sd8q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FYmFJ1ml--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xsm44s2g1sm5b4h3sd8q.png" alt="Alt Text"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2 - Click on the downloaded package
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pp_8Hdah--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2h92gblrresgn5bb0i0a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pp_8Hdah--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2h92gblrresgn5bb0i0a.png" alt="Alt Text"&gt;&lt;/a&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3 - Follow installation steps and complete the installation
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7CSaewzE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5nxdpbai3l96cysij2ly.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7CSaewzE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5nxdpbai3l96cysij2ly.png" alt="Alt Text"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Hurray. You have successfully completed the installation of golang on you mac.&lt;br&gt;&lt;br&gt;
To confirm that golang was installed correctly type the below command in your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt; go version
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you should get this output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;go version go1.14 darwin/amd64
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Having successfully installed mac os let us move to setting it up on mac.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - Setup your workspace
&lt;/h2&gt;

&lt;p&gt;In order to start using go on osx you need to set your environmental variables, this will be used by golang to determines where to find and install new packages.  &lt;/p&gt;

&lt;p&gt;open &lt;code&gt;.bash_profile&lt;/code&gt; file by typing the blow command in your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; nano ~/.bash.profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A new interface on the terminal that looks like this will be shown. &lt;br&gt;
NOTE: Yours will most likely be empty.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ysETh0W4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gla3nqtvvdffospo9fp8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ysETh0W4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gla3nqtvvdffospo9fp8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Set you GOPATH variable to the location of your go folder by typing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export GOPATH=$HOME/go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When Go compiles and installs tools, it will put them in the $GOPATH/bin directory. It is common to add the workspace’s /bin subdirectory to your PATH in your ~/.bash_profile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;export PATH=$&lt;/span&gt;PATH:&lt;span class="nv"&gt;$GOPATH&lt;/span&gt;/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After these have been added your &lt;code&gt;~/.bash_profile&lt;/code&gt; file should look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;export GOPATH=$&lt;/span&gt;HOME/go
&lt;span class="gp"&gt;export PATH=$&lt;/span&gt;PATH:&lt;span class="nv"&gt;$GOPATH&lt;/span&gt;/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ysETh0W4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gla3nqtvvdffospo9fp8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ysETh0W4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gla3nqtvvdffospo9fp8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When done press &lt;code&gt;control + 0&lt;/code&gt; to save the changes then &lt;code&gt;return&lt;/code&gt; then &lt;code&gt;control + x&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To update shell of the new changes type in the below command in your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;. ~/.bash_profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that will be all to confirm that your changes are saved;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;echo ~/.bash_profile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and you should see your variables set.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 - Create first project
&lt;/h2&gt;

&lt;p&gt;When go is installed an auto folder is created on your root directory named &lt;code&gt;go&lt;/code&gt;. This contains your bin, pkg and src folders;&lt;/p&gt;

&lt;p&gt;it is located in your root directory;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fDHk3JHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bltdo5fca9m9zlysvte8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fDHk3JHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bltdo5fca9m9zlysvte8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To test that everything works perfectly run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go get github.com/digitalocean/godo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should the project in the &lt;code&gt;src&lt;/code&gt; directory under the &lt;code&gt;go&lt;/code&gt; directory&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 - Create first go program
&lt;/h2&gt;

&lt;p&gt;Open your terminal in your &lt;code&gt;src/github.com/username/hello-world&lt;/code&gt;&lt;br&gt;
&lt;em&gt;NOTE: Your projects should be structured in that form to aid &lt;code&gt;go get&lt;/code&gt; to run smoothly. &lt;code&gt;Github.com&lt;/code&gt; can be replaced with a link to where your project is.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Run the following command to create a new file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nano hello.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;type in the text file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then &lt;code&gt;control + o&lt;/code&gt; then &lt;code&gt;return&lt;/code&gt; to save and &lt;code&gt;control + x&lt;/code&gt; to return.&lt;br&gt;&lt;br&gt;
To test this type this command in your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go hello.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;OUtput&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also install your new package by typing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go install hello.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and also build;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go build hello.go

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;.&lt;br&gt;
.&lt;br&gt;
.&lt;br&gt;
.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations. You have successfully setup your go workspace on mac OSX &lt;/p&gt;

</description>
      <category>mac</category>
      <category>beginners</category>
      <category>go</category>
      <category>bash</category>
    </item>
  </channel>
</rss>
