Go is an absolutely incredible language to build a wide variety of different applications in. From command-line interfaces to distributed microsystems and even cloud platforms, its’ simplicity and concurrency baked in makes it a powerful choice of language for many development teams.
In this tutorial, I will be embarking on a mission to help get you up and running with the language so that you can go off and build ever-more brilliant applications and help push forward technology.
We’ll be focusing on getting a really simple
Hello World style application up and running. Once you’ve got everything working correctly, we can start the rest of our journey learning the more complex aspects of the language such as functions, methods, and eventually things like concurrency and reflection.
Let’s dive in with getting everything installed and writing an incredibly simple program to get our toes wet.
You’ll first want to go to the official Getting Started page which will contain a link to install the various different versions of Go currently available.
At this point, we’ll want to install the latest version, which, at the time of writing this is
Installing this using the
Installed kind should add the official Go binary to your machine’s
PATH. With this done, we should be able to run
go version within a terminal:
If this works correctly, we are all set to start writing our own Go programs.
Let’s open up our code editor of choice and then create a new directory in which our
Hello World project will reside.
Within this directory, we’ll create a new file called
main.go which will contain our relatively simple Go program. We’ll also want to open up a terminal at this directory location and run the following commands:
This will initialize our project and allow us the ability to separate our Go code into sub-packages in the future. It’ll also allow us to retrieve any external dependencies we may want with minimal fuss.
Now, within our
main.go file, we’ll want to add the following code:
And that’s all you need! Once you’ve added these 5 lines of code, we can set about running and compiling this using our
go binary which is now on our
If we wanted to compile this into a binary executable, we can do so by again using the
go binary like so:
Congratulations - You have successfully written, run and compiled your first Go application!
So, in this simple tutorial, we managed to successfully start our journey into the world of Go development.
If you are interested in further improving your Go skills, I recommend checking out the next article in this series on the basic types available in Go - Go Basic Types Tutorial
Note - If you want to keep track of when new Go articles are posted to the site, then please feel free to follow me on twitter for all the latest news: @Elliot_F.