How to run “headless” virtual machines in OS X

VMWareFusionIconXIf you run multiple operating systems on your Mac in virtual machines, then you likely use either Virtual Box, VMWare Fusion, or Parallels Desktop. For the most part, when you set up a VM on your Mac with any of these solutions, it will run as a window that shows you the graphical view of the virtualized OS. However, if you use your VMs for servers instead of running desktop applications, then you can use a small trick to run them in the background, and thereby save both a little processing power and some desktop clutter.

By default when running VM software will show some virtual machine list window, where you can select your desired VM and launch or configure it. However, when run from these interfaces, a display view to the virtual machine will show. Unfortunately, closing this view will generally suspend or shut down the VM.

For the most part, you might not be too bothered by having a virtual machine window open, since you can hide or minimize it to keep it out of the way; however, if you want a more seamless and “headless” approach for running your VM’s in the background, then the following approaches will do the trick.

Parallels Desktop

  1. Quit Parallels Desktop, if it’s open
  2. Open the Terminal utility
  3. Get a list of the current configured VMs:
    prlctl list -a
  4. Note the name of the VM you want to start, and then start it:
    prlctl start "VM NAME"

VirtualBox

  1. Open the VirtualBox VM list
  2. Hold the Shift key when clicking Start for your VM

VMWare Fusion

  1. Open the Terminal and make an alias to the “vmrun” program (assuming Fusion is installed in the Applications folder):
    alias vmrun=/Applications/VMware\ Fusion.app/Contents/Library/vmrun
  2. Start the vm without the graphical interface:
    vmrun -T fusion start "/path/to/vm.vmx" nogui

Note that making a command alias as shown here is just a temporary way to point to the hidden “vmrun” program. There are more permanent solutions you can use, including soft links, and embedding this alias command in your shell profile.

After running these commands, you will see an indication in the Terminal that the VM is starting, and once done you should be dropped back to the command prompt. From here, you should be able to access all of the services you have configured for your VM, including things like database access, web services, file sharing, and even screen sharing for accessing your VM’s GUI if needed, without any requirement to keep it persistent in an application window.

Note that for each of these commands, as with many command-line tools, running them without any arguments will give you a quick help output that will show you a synopsis of the command’s options. While I have outlined options for starting your VMs in headless modes, you can use the additional options to do things like pause and resume your VMs, restart them, and otherwise manage them while keeping them tucked behind the scenes.

11 thoughts on “How to run “headless” virtual machines in OS X

  1. B. Jefferson Le Blanc

    In my opinion this is an entirely unnecessary procedure. Both Parallels Desktop and VMWare Fusion offer a transparent mode where the Windows desktop is hidden; Windows apps are accessible from the menu bar or the Dock and run to all intents and purposes as if they are running in OS X. If you don’t launch any Windows apps, there is no clutter whatsoever to worry about. In Parallels the mode is called Coherence; in Fusion it’s called Unity. Both of these apps have been able to do this for years. I can’t speak for Virtual Box as I’ve never tried it.

    Unless I’m missing something, this is a solution in search of a problem. If there is one, perhaps Topher can enlighten me as to what advantage his Terminal solution has over either Coherence or Unity.

    Sorry if this sounds snarky, but it’s not like Topher to miss something so obvious.

    1. Strod

      “Unless I’m missing something, this is a solution in search of a problem.”

      The “problem” is indeed mentioned in the article, though Topher probably didn’t emphasize enough on it.

      The scenario is those cases in which people have one, two, or more virtual machines solely to run a service (like a database, a web server, etc.). These services may be running on Windows, but they may be running on separate OS X VMs or on Linux, thus Unity/Coherence may not apply. Even if they all run on Windows, Unity/Coherence may not be a good choice if you are running multiple VMs (not sure about that, though).

      Furthermore, the host OS itself may be running on a headless machine placed in a rack in a datacenter, and managing the VMs via SSH perhaps from the other side of the planet may be extremely convenient.

      1. B. Jefferson Le Blanc

        You’re probably right in the case of someone running more than one VM; Coherence might confuse the issue; though when not in Coherence any number of VMs may be minimized in the Dock if you need to keep the interface handy. As for running headless VMs in a headless VM, I think that’s just too cute for words.

        Still, some people love working in the shell; if that’s your cup of tea, who am I to say you nay?

        As for Mark Isaacspater, methinks thou dost protest too much.

    2. Shad0wLandsUK

      Yep, you certainly have completely misunderstood the article. This when running server version of OSs for use. From the little I understand you only need to have one point of entry for a GUI, when you run servers as you will have a local network setup for all your VMs to talk to one another. Furthermore, some servers do not need a GUI. Take MS Hyper-V for instance. You simply get a command line and then you access all he services and recourses through your command-line. So having a GUI is unneeded. This article is priceless as it does in fact remove clutter. Either you did not understand what is being spoken about here, or you simply misread.

  2. Mark Isaacspater

    Yes, you have utterly misread the article and not understood the point. Please try again.

  3. D_Riz

    This is a great article and just what I needed. Thanks. I am running an Oracle and Jenkins server in the background and didn’t care to have VMware Fusion running in the foreground.

    My only issue now is that if I have them running in the background now, and need to open VMware Fusion to access a VM for testing in windows, and then exit VMware Fusion when I’m done, the original VMs running in the background are shutdown or paused when I exit Fusion. I have to run them from the command line again to start them back up.

    Any ideas to avoid that? Its a small annoyance but I’d rather not have to do that. I was wondering how to run a separate instance of VMware Fusion just for the background VM servers.

  4. gia xe hoi

    Hello friends, nice piece of writing and good arguments commented at this place, I am genuinely
    enjoying by these.

  5. Jose Malena

    Hi, good article, that is exactly what I need, for starting 3 VMs with my services (db, routing, web) in headless mode and have a virtual Datacenter for development.

    I’m using VMWare Fusion and I get this error after testing with alias:
    [jmalena@:MacMini ~]$ alias vmrun=/Applications/VMware\ Fusion.app/Contents/Library/vmrun
    [jmalena@:MacMini ~]$ vmrun
    -bash: /Applications/VMware: No such file or directory

    1. Ruairi Newman

      Use quotes around the path to vmrun, i.e.

      alias vmrun=’/Applications/VMware\ Fusion.app/Contents/Library/vmrun’

    2. Strod

      Note that in Ruairi Newman’s reply the straight single quotes got replaced with “typographic” (AKA “curly”) single quotes.
      So don’t just copy and paste the line he suggested, or you will get a similar error. Instead, make sure you replace with straight quotes (both single and double will work as long as you open and close the path with the same kind).

      As a side note: In the firs line of this reply I used only straight double quotes. But if things go like I expect you are seeing *curly* double quotes instead. This is an annoying auto-formatting feature of the web form.

Comments are closed.