Building a Cross-Platform Go Binary

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

One of Go’s greatest features is that it can be used to build statically linked cross-platform binaries. In this learning activity, you’ll go through the process of taking an existing Go application and building separate binaries for a few different Unix-based operating systems: Linux, macOS, and FreeBSD.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Compile an `hr` Binary for Linux

The primary operating system that the hr utility will be used on is Linux. Compile a binary that can run on Linux systems like your workstation. Call this binary hr.linux.

Compile an `hr` Binary for macOS

Compile a binary that can run on macOS systems. Call this binary hr.darwin.

Note: The operating system identifier is darwin.

Compile an `hr` Binary for FreeBSD

Compile a binary that can run on macOS systems. Call this binary hr.freebsd.

Additional Resources

You've created a tool that will allow you to export user information from a system into JSON or CSV format, and you're ready to deploy it to various machines within your organization. Your organization utilizes Linux, macOS, and FreeBSD machines and you want to have access to your utility on all of the machines. Using Go's ability to build cross-platform applications, you're going to compile three different binaries, one for each operating system.

Note: All of the target machines utilize the AMD64 architecture.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?