Skip to main content
Go Language Fundamentals for Beginners to Advanced
CHAPTER 02 Beginner

Installing Go and Setting Up Environment

Updated: May 17, 2026
5 min read

# CHAPTER 2

Installing Go and Setting Up Environment

1. Introduction

Before we can write high-performance backend systems, we need the tools to build them. In this chapter, we will download the Go compiler, configure our operating system to recognize Go commands, and set up a professional Integrated Development Environment (IDE) using Visual Studio Code.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Download and install Go on Windows, macOS, or Linux.
  • Verify the installation using the terminal.
  • Understand the historical concepts of GOROOT and GOPATH.
  • Install and configure Visual Studio Code (VS Code) for Go development.

3. Downloading and Installing Go

Go is entirely open-source and free.

Step 1: Download the Installer

  1. 1. Navigate to the official website: https://go.dev/dl/
  1. 2. Download the installer matching your Operating System (Windows .msi, macOS .pkg, or Linux .tar.gz).

#### Installing on Windows

  1. 1. Double-click the downloaded .msi file.
  1. 2. Follow the prompts and accept the default installation path (usually C:\Program Files\Go).
  1. 3. The installer automatically adds Go to your system's PATH environment variable.

#### Installing on macOS

  1. 1. Double-click the .pkg file and follow the installation wizard.
  1. 2. Alternatively, if you use Homebrew, simply open your terminal and run:

bash
12345678910111213141516
   brew install go
   ```

#### Installing on Linux (Ubuntu/Debian)
1. Remove any old Go installations and extract the new archive:
   ```bash
   rm -rf /usr/local/go && tar -C /usr/local -xzf go1.x.x.linux-amd64.tar.gz
   ```
2. Add Go to your PATH by adding this line to your `~/.profile` or `~/.bashrc`:
   ```bash
   export PATH=$PATH:/usr/local/go/bin
   ```
3. Run `source ~/.bashrc` to apply the changes.

### 4. Verifying the Installation
Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux) and type:

bash go version

123456789101112131415161718192021222324252627282930313233
*Output Example:* `go version go1.21.0 windows/amd64`
If you see this, Go is successfully installed!

### 5. Understanding GOROOT and GOPATH
If you read older Go tutorials (pre-2019), you will see heavy mentions of `GOROOT` and `GOPATH`. 
*   **`GOROOT`:** Where the Go compiler and standard library are installed (e.g., `C:\Program Files\Go`). You rarely need to touch this.
*   **`GOPATH`:** In the old days of Go, *all* your projects had to be strictly placed inside a specific `GOPATH/src` folder. 

**Modern Go (Go Modules):**
Since Go 1.11, Go introduced **Go Modules**. You no longer need to worry about `GOPATH`. You can create your Go projects in any folder on your computer (e.g., your Desktop or Documents folder) just like Python or Node.js!

### 6. Setting Up Visual Studio Code (VS Code)
Writing Go in Notepad is painful. We will use Visual Studio Code, the industry standard for Go development.

1. Download and install VS Code from [code.visualstudio.com](https://code.visualstudio.com/).
2. Open VS Code.
3. Click on the **Extensions** icon on the left sidebar (or press `Ctrl+Shift+X`).
4. Search for **"Go"** (the official extension published by the Go Team at Google) and click **Install**.

#### Installing Go Tools in VS Code
Once the extension is installed, VS Code needs to download helper tools (for formatting, debugging, and autocomplete).
1. Press `Ctrl+Shift+P` (Windows) or `Cmd+Shift+P` (Mac) to open the Command Palette.
2. Type `Go: Install/Update Tools` and press Enter.
3. Check the box at the top to select all tools, then click **OK**.
4. Wait for the terminal to finish installing the tools.

### 7. Creating Your Workspace
Let's prepare a folder for all the code we will write in this course.
1. Create a folder named `golang-course` anywhere on your computer.
2. Open VS Code.
3. Go to `File > Open Folder` and select `golang-course`.

To initialize this folder as a modern Go project, open the VS Code integrated terminal (`Ctrl + ~`) and run:

bash go mod init golang-course `` This creates a go.mod file, which manages any third-party dependencies (similar to package.json in Node.js).

8. Common Mistakes

  • "go is not recognized as an internal or external command" on Windows: This means the Go installer failed to add Go to your System PATH. You will need to manually add C:\Program Files\Go\bin to your Environment Variables.
  • Writing code outside a Module: Always run go mod init <project-name> when starting a new project folder. Without it, VS Code might show false errors.

9. Best Practices

  • Keep Go Updated: The Go team releases major updates every 6 months (February and August). Keeping your compiler updated ensures you have the latest performance improvements and security patches.
  • Use gofmt: Ensure your VS Code is set to "Format on Save" so it automatically runs gofmt every time you save a file.

10. Exercises

  1. 1. Install Go and verify it by running go version in your terminal.
  1. 2. Install VS Code, add the Go extension, and install the required Go tools.
  1. 3. Create a folder named my-first-go, open it in VS Code, and run go mod init my-first-go in the terminal.

11. MCQs with Answers & Explanations

Question 1

What command verifies that Go is installed correctly?

Question 2

What does GOROOT represent in Go?

Q3. Do modern Go projects strictly require you to place your code inside the GOPATH/src folder? a) Yes b) No Answer: b) No. *Explanation: With the introduction of Go Modules, you can place your code anywhere on your hard drive.*
Question 4

What is the official IDE extension for Go development in VS Code?

Question 5

What command initializes a new Go Module in your current directory?

Question 6

What file is generated when you run go mod init?

Question 7

If your terminal says "go is not recognized", what is likely the problem?

Question 8

Which of the following is true about installing Go?

Question 9

Why does the VS Code Go extension download additional tools?

Question 10

How often does the Go team release major updates?

12. Interview Preparation

Interview Questions:
  1. 1. What is the difference between GOPATH and Go Modules?
  1. 2. How does dependency management work in modern Go compared to Node.js or Python?

Debugging Task: If a junior developer cannot run their Go code because of a "missing go.mod" error, how would you instruct them to fix it? (Answer: Open terminal in project root and run go mod init [project_name]).

13. FAQs

Q: Do I have to use VS Code? A: No, you can use any editor like IntelliJ (GoLand), Vim, or Sublime Text. However, VS Code is free, highly supported by the Go team, and perfect for beginners.

Q: Does Go run on Apple Silicon (M1/M2 chips)? A: Yes! Go provides native ARM64 binaries for Apple Silicon, resulting in incredibly fast compile and execution times on modern Macs.

14. Summary

Setting up a Go environment is straightforward. You download the compiler, verify it in the terminal, and set up a modern IDE like VS Code. By using
go mod init, we embrace modern Go practices, freeing ourselves from the legacy restrictions of GOPATH`.

15. Next Chapter Recommendation

With our tools installed and configured, the real fun begins! In Chapter 3: Go Syntax and First Program, we will write, compile, and execute our very first "Hello, World!" application in Go.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·