Getting started
Learning a new language for the first time is no easy feat! However, keep in mind that every Go developer, no matter how skilled, was once in your shoes: learning the syntax and inner workings of the language for the first time.
Be sure to make use of all the resources available to you, and maintain a constant rhythm. Throughout this book, you’ll have many opportunities to practice the Go skills you’ll pick up along the way (especially those that you’ll need for your entire go career!). By leveraging your creativity and problem-solving skills, I know you’ll find development with Go rewarding. Good luck!
Step-by-Step Guide for Installing Go
Getting Go installed on your local machine is straightforward. If you’re using Linux, Mac, or Windows, you can download and execute an installer to get up and running immediately.
Installing Go on Windows
To install Go on Windows, follow these steps:
- Download the Windows installer from the official Go website: https://golang.org/dl/
- Double-click on the installer to start the installation process.
- Follow the prompts to complete the installation. Choose the default options unless you have a specific reason to change them.
- Once the installation is complete, open the Command Prompt or PowerShell and type go version to verify that Go is installed correctly.
Installing Go on Mac
To install Go on a Mac, follow these steps:
- Download the macOS installer from the official Go website: https://golang.org/dl/
- Double-click on the installer to start the installation process.
- Follow the prompts to complete the installation. Choose the default options unless you have a specific reason to change them.
- Once the installation is complete, open the Terminal app and type go version to verify that Go is installed correctly.
Installing Go on Linux
To install Go on Linux, follow these steps:
- Open a terminal window.
- Update the package list by typing
sudo apt update
(for Debian/Ubuntu) orsudo yum update
(for CentOS/Fedora). - Install the Go package by typing
sudo apt install golang
(for Debian/Ubuntu) orsudo yum install golang
(for CentOS/Fedora). - Once the installation is complete, type
go version
to verify that Go is installed correctly.
If you still have issues after following the instructions above, you can checkout the official website Download and Install
Setting Up Environment Variables
After the installation steps covered above,it’s time for us to set up environment variables necessary for running go programs and using go tools.
Setting Up Environment Variables on Windows
- Open the Control Panel and go to System and Security > System > Advanced system settings.
- Click on the Environment Variables button.
- Under System Variables, click on New.
- Enter the following information:
- Variable name:
GOROOT
- Variable value:
C:\Go
(or the directory where Go is installed)
- Variable name:
- Click on OK to save the variable.
- Under System Variables, click on New again.
- Enter the following information:
- Variable name:
GOPATH
- Variable value:
%USERPROFILE%\go
(or the directory where you want to store your Go projects)
- Variable name:
- Click on OK to save the variable
Setting Up Environment Variables on Mac/Linux
Here the steps are both same for Mac and linux
- Open the Terminal app.
- Type
nano ~/.bash_profile
to open the Bash profile file. - Add the following lines to the file:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
- Press
Ctrl+X
, thenY
, then Enter to save the file and exit Nano. - Type source
~/.bash_profile
to reload the Bash profile.