77

In several languages, instead of returning something like "macOS", the command to view the operating system instead returns

Darwin

I see this in languages like R, and node.

Why is macOS sometimes called Darwin??

anki
  • 11,753
stevec
  • 4,955
  • 3
    It is for the same reason that Ubuntu OS is often called "Linux" or RaspberryPi OS is called "Linux" - Linux is not an OS. It is a kernel that can be used as the core of your OS. Which is why we call Android an OS even though it uses the Linux kernel – slebetman Sep 23 '20 at 16:25
  • 8
    Darwin, however, is an OS, not just a kernel (the kernel is called xnu). Apple used to make it available as a separate OS, complete with binaries, installer, ISOs, etc., but they stopped many years ago. – Jörg W Mittag Sep 23 '20 at 18:26
  • 3
    MacOS is the whole package. Darwin does not have the Aqua GUI so it is plain text or - like most other Unix/Linux variants - an X11 GUI. – Thorbjørn Ravn Andersen Sep 24 '20 at 10:09

5 Answers5

106

Why is macOS often referred to as 'Darwin'?

It isn't. macOS isn't Darwin and Darwin isn't macOS.

The history of macOS is long, convoluted, and complicated.

It starts with Steve Jobs (not entirely voluntary) "leaving" Apple and founding NeXT. NeXT wanted to revolutionize the Personal Workstation. They built both a powerful computer, the NeXT Computer (later NeXTstation and NeXTcube), and a powerful, modern Operating System, called NeXTStep. (Get it? The next step for the next computer. Really creative naming.)

The Operating System was based on porting BSD to a Mach microkernel, and adding object-oriented system libraries, frameworks, and toolkits (called "kits", which you can still see in Apple's naming today), with an object-oriented GUI framework and desktop, with object-oriented applications, all written in a modern object-oriented programming language (Objective-C) as the systems language, on top of the base BSD system. The display system was based on PostScript, and there was even an Intel i860 coprocessor running a stripped-down version of the OS, only for Display PostScript processing, plus a powerful DSP for video and audio processing.

NeXTStep pioneered many things we see in modern GUI programming. It had one of the first graphical GUI Builders, which still to this day is how you design GUIs for macOS, iOS, iPadOS, etc. (Today, it is called the Xcode Interface Builder.) It had the first ever App Store. When Tim Berners-Lee invented the World Wide Web, he chose NeXTStep as the OS to write the first browser for. Many game studios used NeXTStep and NeXT workstations for their development, e.g. id software for Doom, Doom 2, and Quake. Lotus Improv, still considered by many to be miles ahead of Excel even now, was implemented on NeXTStep.

Later, NeXT divorced the higher-level frameworks from the underlying OS and made them available under the name OpenStep for Windows NT, Sun Solaris, and under the name "OPENSTEP for Mach" still based on the same underpinnings as the original NeXTStep.

At this point, Apple had tried and failed multiple times to modernize MacOS, and they bought NeXT (thus bringing Steve Jobs back into the company) and all of its Intellectual Property and technology to develop a successor to MacOS based on OPENSTEP for Mach. They modernized the Mach kernel from 2.5 to 3 and extended it with concepts from the FreeBSD kernel to form a kernel known as xnu (a reference to the failed nuKernel project at Apple which was to develop a "new kernel"), and the BSD underpinnings from 4.3BSD to 4.4BSD and later FreeBSD.

Most importantly, they extended and expanded the OpenStep APIs and built new APIs on top. The collection of those APIs is known as "Cocoa". They also built an API called "Carbon", which was a close, but not identical re-implementation of a subset of the MacOS API on top of the new foundations. (The intention was that while it would not be possible to simply re-compile existing MacOS applications, it should be fairly easy to port them to Carbon, and then over the years rewrite them in Cocoa.)

The first prototype of this system was called Rhapsody. The full system wasn't finished in time, so a subset was released as MacOS X Server 1.0. And the rest is history: Rhapsody became MacOS X, then OS X, then macOS, and somewhere along the way, iOS was split off, and then further divided into iOS, iPadOS, tvOS, and watchOS.

Now, back to Darwin: Darwin is basically the underpinnings of macOS, from the xnu kernel, IOKit, drivers, etc. up to the BSD libraries and userland, plus some macOS-specific developments such as mDNSresponder and launchd. It does not, however, include any parts of what used to be OpenStep, Cocoa, Aqua, Quartz, QuickTime, or any of the other higher-level stuff. It does contain drivers and filesystems, although I am not entirely sure whether APFS is part of Darwin.

If you think back to the point in time where NeXT "divorced" the high-level OpenStep from its underpinnings, the low-level parts that are not OpenStep would be the ones that would later become Darwin.

In the beginning, Apple used to make Darwin available as a separate OS, including compiled binaries, installers, ISOs, etc. that you could install on Apple hardware. However, for many years now, Apple only provides a source code dump, every time a new release of macOS comes out. It isn't even possible to compile this source code, because it depends on Apple's internal build tools and build pipeline. There have been some projects trying to patch Darwin to compile it with publicly available tools, but those projects have all died from lack of interest.

Since all of the things you mentioned were born on Unix and use Unix APIs and Unix libraries, they actually typically don't even know about the "non-Darwin" parts of macOS, so it is only logical that they will consider the OS to be "Darwin". Note that "Darwin" is also what gets returned as the name of the OS when you call the Unix/POSIX int uname(struct utsname *buf) library function or the uname Unix/POSIX commandline utility.

So, to answer the question you didn't ask explicitly but is implicit in your question: why does Node.js return "Darwin" for the name of macOS? Because when Node.js asks macOS for its name, that's what macOS tells it its name is!

  • 2
    Funfact: Sun also had a display server using postscript called NeWS, however it failed to have competitive performance compared to W and later X. – ljrk Sep 23 '20 at 19:58
  • 1
    Presumably the reason why Darwin has its own identity is that because it's based on open-source foundations, it must be made available as open source?  And obviously Apple don't want to release any of the higher-level stuff, so that must be kept separate from Darwin? – gidds Sep 23 '20 at 21:39
  • 13
    @ljrk: There are many, many fun facts surrounding Sun and the history of macOS. Patrick Naughton, a developer at Sun disliked C++ and was a huge fan of Objective-C, so he decided to quit Sun and work at NeXT. However, shortly before he left, he ran into Scott McNealy, who told him about a super-secret project to develop a new language at Sun, and if he had such strong opinions about language design, he should direct his inputs there. So, Naughton joined the Oak (later Java) team as one of the lead designers. Later, during NeXT's decline, several other high-level Objective-C and NeXTStep … – Jörg W Mittag Sep 24 '20 at 00:24
  • 11
    … developers left NeXT to work on Java. Many people are blinded by the C-like syntax or comparisons with C++, but Java is almost a carbon copy of Objective-C with static types and garbage collections. (interface is directly cribbed from protocol, for example.) Also, large parts of the core libraries are influenced by NeXTStep, for example, all the wrapper classes were designed by NeXTSteppers. That's why they're called Integer, not Int, for example, because the NeXTStep guys valued clarity over keystrokes. And the other thing is that apart from Rhapsody, Apple also worked on another – Jörg W Mittag Sep 24 '20 at 00:27
  • 9
    … (failed) next-gen OS together with IBM, called Taligent. Like NeXTStep, Taligent also morphed from a complete OS into a class library ported to multiple existing OSs. And Taligent was both a huge influence on Swing, and a smaller influence on Aqua. That's why the Java integration with Apple's own JDK was so amazing: Java and Objective-C are very closely related, the core Java libraries and Cocoa are closely related, and there are common "genes" between Swing and Aqua. This, together with Apple's approach of deeply integrating the JDK with Objective-C/Cocoa and Swing with Aqua made for … – Jörg W Mittag Sep 24 '20 at 00:31
  • 9
    … "close-to-native" Java experience, at least as long as Apple supported Java. Nowadays, unfortunately, we have to make do with a "generic" JDK that runs on many OSs instead of Apple's tailor-made one. Apple did the same thing with Ruby: they developed MacRuby, a tightly integrated Ruby implementation (again, Objective-C and Ruby share Smalltalk as a common ancestor, so it was possible to deeply integrate them.) – Jörg W Mittag Sep 24 '20 at 00:33
  • 6
    @gidds: Most of what Darwin is based on, is BSD-licensed, so there is no requirement for Apple to release the source code. It's more of a courtesy thing, I guess. If you stand on the shoulders of giants, it's a good idea to not piss on them from up high. Note that as I mentioned, the way that Apple releases the source code is fairly useless. You cannot compile it without Apple's internal build tools, you don't get version history, only a code drop every couple months, you don't have access to issue trackers, discussions, etc., so if you find a comment in the code saying "fixes bug #23", you … – Jörg W Mittag Sep 24 '20 at 00:38
  • 6
    … have no idea what they are talking about, etc. It was more useful back in the days when Apple released binary builds, installers, and ISOs as well, and you could compile Darwin on Darwin. Nowadays, the only remaining usage is as a reference for how things work, if you need to really dive down deep into the kernel. And yes, Apple keeps all the higher-level proprietary because, well, for the same reason every other proprietary OS vendor keeps their stuff proprietary. – Jörg W Mittag Sep 24 '20 at 00:38
  • Some nitpicking for the sake of learning and interest. If I run the R command that should return the operating system name (from an unmodified 2019 macbook pro): Sys.info()['sysname'] returns "Darwin". Technically speaking, is that wrong? – stevec Sep 24 '20 at 03:10
  • 8
    @stevec: That is what Apple programmed the library call that returns the system name to return, so at least according to Apple, that is correct. Whether you consider that "right" or "wrong" is a question that only you can answer. Note that I am 100% sure that you are not using a native macOS implementation of R but rather the standard Unix version, so it makes sense that it returns the name of the Unix system underpinning macOS. In fact, if the separate Darwin OS were still a thing, it would probably run unmodified there. – Jörg W Mittag Sep 24 '20 at 05:54
  • 5
    @stevec: Note that a Unix application running on Debian will also return "Linux", as will one running on Ubuntu, Raspberry Pi OS, Mint, SuSE, Fedora, RedHat, White Box, CentOS, Oracle Linux, Gentoo, Windows Subsystem for Linux, Arch, Manjaro, Alpine, Deepin, Kali, elementary, Zorin, Chromium OS, Slackware, NixOS, Puppy, Tiny Core, OpenWrt, Firefox OS, … – Jörg W Mittag Sep 24 '20 at 06:08
  • 1
    @JörgWMittag Wow, what a read (and I totally get the detest of C++ hehe). Another thing SunOS and MacOS X have in common is that they are officially POSIX certified, or UNIX™, which is also probably a reason why system functions return Darwin: The UNIX/POSIX programming interface is identical to the one exposed by Darwin. So much to unpack! – ljrk Sep 24 '20 at 08:51
  • 1
    Awesome, thanks for all this. Maybe you even could include the comments into the answer, they are helpful to complete the picture. – nohillside Sep 24 '20 at 12:21
  • "Lotus Improv, still considered by many to be miles ahead of Excel even now" Citation desperately need for such a grossly misguided claim. No one thinks this, or it would not have died in the 90s along with Lotus 1-2-3 while Excel continued its (still-growing) rise in popularity. – TylerH Sep 24 '20 at 18:38
  • 1
    "However, for many years now, Apple only provides a source code dump, every time a new release of macOS comes out. It isn't even possible to compile this source code, because it depends on Apple's internal build tools and build pipeline." Are you sure of that? AMD Hackintosh users used to compile custom Darwin kernels as recently as two years ago. My understanding is that they stopped only because binary patches ended up being more convenient—you don't need to copy back your custom kernel after every update. – Wowfunhappy Oct 01 '20 at 03:39
  • 1
    So. Darwin used to be a separate OS, but no longer is, but we can assume the source code is required to compile and build macOS. It is published to the public but can't be build by itself because it relies on apple internals? Is that right?

    Sounds like "Technical debt" :-)

    – Glenn Bech Oct 03 '21 at 10:40
28

Darwin is the core upon which macOS (previously Mac OS X, and OS X) runs on.

It is derived from NextSTEP, which itself is built upon a BSD and Mach core, but Darwin is the open source portion of macOS.

Historically, when Apple bought NeXT in the late 1990s, they built upon the NeXT operating system (NeXTSTEP) to form the basis of the next version of the OS for the Mac.

See Wikipedia's Darwin entry for more details.

Scott Earle
  • 4,006
  • 14
    Darwin is not the kernel. The kernel is xnu, which in turn is composed of multiple services running on a modified Mach microkernel. – Jörg W Mittag Sep 23 '20 at 16:53
  • 1
    If you change "kernel" to "core" or "core OS", your answer would be correct. The word "kernel" have a very specific definition is the UNIX world and Darwin is not the kernel, Darwin is between the kernel (XNU) and the final OS/distribution (macOS, iOS, etc.). – zakinster Sep 24 '20 at 08:02
  • 1
    After the edit this is better but I still think > derived from NeXTSTEP ... built upon a BSD and Mach core < is not really "correct". XNU is part of Darwin and based on a BSD-ified Mach Kernel. Darwin also contains other BSD libs and BSD core utils. So it's more like: Darwin = XNU + Userland, with Userland being of BSD heritage and XNU of shared BSD and Mach heritage – ljrk Sep 24 '20 at 08:57
11

There are lots of ways to fingerprint an OS, but a canonical method for this on unix-like systems is to call uname Which outputs Darwin on all macOS versions and builds.

Apple publishes the source code to the Darwin part of the OS so you can inspect the code that matches the name.

https://opensource.apple.com/release/mac-os-x-100.html

If you want to see this yourself, open a shell (in Terminal.app) and you can generate the Darwin string and read the manual page for uname command or the system call (man 3)

uname
man uname
man 3 uname

Here's a nice example of a program needing to know which system is running by calling uname from a shell script. It then adjusts syntax and variables to do the same task on various OS:

I'll leave the "Why did human beings do this" for another time - that story is rich and multifaceted and there's tons of stories documented publicly on the Internet for the curious.

bmike
  • 235,889
  • 5
    Slight nit:uname isn't programmed to answer Darwin; it's programmed to look at known external resources to find the name of the platform it is running on. – chepner Sep 23 '20 at 13:31
  • 1
    I'm pretty sure YARV doesn't shell out to the uname command. It is more likely, it uses the int uname(struct utsname *buf) POSIX library call. – Jörg W Mittag Sep 23 '20 at 16:57
  • @JörgWMittag your answer is stellar as are the comments here. Thanks all for the information and thoughtful points made. – bmike Sep 24 '20 at 17:06
8

From Wikipedia, Darwin is an open-source Unix-like operating system first released by Apple Inc. in 2000. It is composed of code developed by Apple, as well as code derived from NeXTSTEP, BSD, Mach, and other free software projects.

Natsfan
  • 14,185
  • 3
    And the next line in the wikipedia article : "Darwin forms the core set of components upon which macOS, iOS, watchOS, tvOS and ipadOS are based" explains why macOS is sometimes technically reffered to as a "Darwin" OS. – zakinster Sep 24 '20 at 07:59
2

Here is a quote from the book Take Control of the Mac Command Line with Terminal

When Apple bought NeXT in 1996, they began building a new operating system that extended and enhanced NeXTSTEP while layering on capabilities (and some of the user interface) of the classic Mac OS. The result was Mac OS X (later renamed OS X and now macOS): it’s Unix underneath, but with lots of extra stuff that’s not in other versions of Unix. If you took macOS and stripped off the graphical interface, the Cocoa application programming interfaces (APIs), and all the built-in apps such as Mail and Safari, you’d get the Unix core of macOS. This core has its own name: Darwin. When you work in the command-line environment, you’ll encounter this term from time to time.