Getting Compilers

Joaquín Menchaca (智裕)
4 min readNov 30, 2018

--

In my youth, a seasoned Linux guru commented how any new computer without a compiler, is not a computer. As my knowledge grew, and given the popularity in open source, this made sense. Often, I am required use compilers when installing tools or libraries needed for popular platforms like Ruby, Python, and Node.js.

And so, this article is about getting compilers.

Below is an overview and howtos show how get compilers with macOS, Windows, and Linux (Debian and RHEL families). I also introduce package managers: Homebrew for macOS and Chocolatey for Windows.

Compiler Overview for the Uninitiated

So what is a compiler anyway, and why do you need it?

Everything You Didn’t Want to Know

A compiler today is basically refers to collection of tools that allow us to build software, and is a requirement for many open source tools installs. These toolsets, like GCC or Clang, have two parts, the compiler tool itself and the linker.

The compiler tool converts human readable source code to machine code that a specific processor can understand. Each processor, such as Sparc, PowerPC, Arm, or Intel have their own unique machine code, so software will need to be compiled on each of these.

In modern platforms or frameworks, the compiler tool will convert to bytecode that is usable by an application virtual machine, such as JVM (Java Virtual Machine), or .NET Framework CLR (Common Language Runtime). This bytecode is then itself compiled into machine code during runtime (or link time). This makes the software more portable across different processors.

The linker tool creates an executable that will run on a particular operating system. It does this by linking your code with libraries and some code that will make it work on a particular operating system or application virtual machine. Where the compiler was specific to a specific processor, a linker is specific to an operating system, such as Linux, Windows, macOS, or FreeBSD.

This article focuses on compilers tool sets needed to get open source projects installed, like python and ruby. We will not cover an AVM like JVM or .NET CLR, as those are complex enough to have their own articles.

And Why?

These days, many open source tools and applications, and well, just cool stuff, requires compilers. If you work in operations, development, quality assurance, and other roles, you simply cannot avoid need to use compilers.

For most of us, we just need the command line tools. If you need to edit the code, you can use vim or other popular text editors, or an IDE (Integrated Development Environment) that provides graphical interface to do step-by-step debugging.

macOS

Apple goes out of their way to push you toward using Apple Store to download their graphical IDE, but you really don’t need to get that. For most cases, all you need is to get the command line tools.

Installing Command Line Tools

For that, you can get the tools by running this:

xcode-select --install

On Apple’s newest incarnation, macOS 10.14 Mojave, Apple decided that command line tools, like compilers, don’t need headers to do, um, compiling. The result, is that you cannot install many open source tools, because compilers no longer work. In order to ameliorate this, you need to run this:

# Mojave only - need headers or nothing works
TOOLS_PATH="/Library/Developer/CommandLineTools/"
HEADERS_PKG="macOS_SDK_headers_for_macOS_10.14.pkg"
sudo installer -pkg $TOOLS_PATH/Packages/$HEADERS_PKG -target /

After running this, using tools that require compilers, as many do with Homebrew packages, will now work.

Installing Homebrew

Once you have command line tools with both compilers and the headers that compilers need, you may want to install some packages with Homebrew.

PREFIX="https://raw.githubusercontent.com"
SCRIPT_PATH="Homebrew/install/master/install"
ruby -e "$(curl -fsSL $PREFIX/$SCRIPT_PATH)"

XCode

You can download Apple’s graphical IDE, XCode, either from Apple Store, or directly from https://developer.apple.com.

Apple will try to hide the link, but can still download the current XCode 10.1 from:

The nice thing about downloading manually, is that can then copy and install on other computers, saving the need to download ~7 GB each time for every computer.

Automating this process requires sending credentials and using web cookies, complex in and of itself. There’s some notes about this from:

Windows

On Windows, in order to get command line compiler tools, you need to install a full IDE called Visual Studio. The free community edition is fine. This program requires installation of .Net Framework 4.5.1 (or better, a more recent 4.x version).

You can install these and fetch other dependencies, or just use a package manager like Chocolatey.

Installing Chocolatey

Once you have Chocolatey installed, you can install compilers and other packages available in the public domain for Windows. In PowerShell in Administrator mode.

Set-ExecutionPolicy Bypass -Scope Process -Force; 
$script_url = 'https://chocolatey.org/install.ps1'
iex ((New-Object System.Net.WebClient).DownloadString($script_url))

Installing Compilers

With Chocolatey, you can compilers and dependencies by running this in Powershell in Administrator mode:

choco install -y microsoft-build-tools
refreshenv

Linux

Linux, as you can imagine, is straightforward.

Ubuntu 16.04

This works on Debian family of distributions, like current versions Ubuntu, Mint, and Debian.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential

CentOS 7

This works on RHEL based distributions like CentOS and Amazon Linux. It should work on Fedora as well.

sudo yum -y update
sudo yum
group install "Development Tools"

Wrapping Up

When writing tutorials, I found myself re-documenting how to get core essential tools like compilers, and so I wanted to get this out there, and just reference this common blog.

I also wanted to document a solution where getting compilers that works with most open source is not so obvious.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Joaquín Menchaca (智裕)
Joaquín Menchaca (智裕)

Written by Joaquín Menchaca (智裕)

DevOps/SRE/PlatformEng — k8s, o11y, vault, terraform, ansible

No responses yet

Write a response