33

Is there a way to run a Linux binary in macOS? I tried to run a binary but it said it isn't executable.

4
  • This will not work. The OSX kernel is somewhat different from a Linux kernel.
    – ott--
    Commented Jun 28, 2015 at 23:12
  • Well OS X does not use elf binaries, so it's a bit like trying to run windows .exe. However, a brief search finds this: osxbook.com/software/xbinary If you can recompile your code, it's not an issue.
    – orion
    Commented Jun 29, 2015 at 9:01
  • XBinary requires a program that knows how to run your binary; it in and of itself doesn't run anything.
    – saagarjha
    Commented Apr 14, 2018 at 23:37
  • @ott-- You can use "wine" to run Windows binary on Linux. Maybe there is a wine-like thing to run Linux binary on macOS.
    – Victor
    Commented Jul 22, 2021 at 3:53

4 Answers 4

26

Update years later: The Noah repo has now been archived. I haven't found a good alternative.


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.

2
  • 1
    though the command worked and no errors did rise, my binaries did not work as expected
    – techkuz
    Commented Dec 18, 2019 at 7:48
  • 4
    Outdated answer, it does not work anymore. noah has been removed from homebrew and the source code is archived.
    – Victor
    Commented Jul 30, 2021 at 2:31
13

These answers are half correct, because virtualization is a choice but there is another. May I present...

History

  1. First there was UNIX, circa 1972
  2. 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:

  1. Install XCode for your version of OS X.
  2. 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.)
  3. 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?

3

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.

2

Hardware Emulation

Not directly! Yes as rocky said, you have to virtualize it with VirtualBox, VMWare Fusion, which will match your CPU type.

There's also Qemu, which will virtualize different CPU types i.e. Intel or Power etc.

Software Emulation

There is also software layer emulation, with programs like WiNE, and my own emulayer program(WiP) Both of these partially emulate the Windows OS by converting the system calls to POSIX.

Most Linux applications will run on OSX with a source recompile.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .