Is there a way to run a Linux binary on macOS?
I recently starting using Noah to run Linux binaries in macOS. You can install using homebrew (brew install linux-noah/noah/noah
). Then you should be able to do this:
noah linux_binary
In my experience the behavior of the binary matches what I see on my Ubuntu machine.
These answers are half correct, because virtualization is a choice but there is another. May I present...
History
- First there was UNIX, circa 1972
- Then the Timeline Split
- In 1977, for $90, Bob Fabry and others, compiled/built the first versions of BSD, short for Berkeley Systems Distribution.
- In 1991, Linus Torvalds posted in a Newsgroup, about software he used from Richard Stallman, who started GNU in 1983, and Linus'es UNIX was born.
- Apple reacquired NeXT Software in 1996, after Steve Jobs was fired from Apple in 1984, and used the software and people there to build OS X. OS X is the Darwin OS + the NeXT Desktop Environment. And now we're back to Bullet #1, as Darwin is a closed source fork of BSD. For the Open Source Project, see PureDarwin. For the Official Apple Developer Page, see Apple Open Source.
How We Can Use This
BSD's traditionally use the Ports system for Package Management. The most widely used of these are the FreeBSD Ports. Ports are packages installed directly from source. Since the same Linux applications come from the same sources, you can run a Linux application if its port exists. Don't use these Ports on a Mac because...
Since all of Apple's GUI's are written using the Cocoa API - WikiEntry, bundled with XCode - OS X for Developers, the Ports can be tuned to take advantage of this:
- Install XCode for your version of OS X.
- Bundled inside XCode is Apple's version of the GCC Compiler, and all the other associated tools. To update the tools, see this post on StackOverflow. The tools are OS Version dependant, ie they are not backwards compatible, to my knowledge (in short, don't install XCode for 10.8 on 10.6, etc.)
- Having installed XCode you now have a compiler, and can head on over to the MacPorts page and browse for the port you need installed, after installing the MacPorts .pkg installer
Caveat
The ports system doesn't necessarily do dependency checking, unless the port was well written. I lightly touched on the problem in what does elibc_FreeBSD mean in gentoo portage overlays?
The only way I know that this can be done via some sort of virtualization. For example, you could use vagrant which is a wrapper of sorts around Oracle's VBox or VMware's vmplayer. The other thing that is sometimes done is put this in a container such as docker.