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.
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.
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.
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:
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
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.
Once you have command line tools with both compilers and the headers that compilers need, you may want to install some packages with Homebrew.
ruby -e "$(curl -fsSL $PREFIX/$SCRIPT_PATH)"
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:
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.
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))
With Chocolatey, you can compilers and dependencies by running this in Powershell in Administrator mode:
choco install -y microsoft-build-tools
Linux, as you can imagine, is straightforward.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential
sudo yum -y update
sudo yum group install "Development Tools"
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.