Is there a way to run a Linux binary on macOS?

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

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?

Method 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.

Method 4

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x