How to install Mono on macOS so mono works in terminal?

75,474

Solution 1

Update (since this is still getting views two+ years later):

The latest versions of Mono (5.x) installation process creates a file (mono-commands) in /etc/paths.d that contains the path of:

/Library/Frameworks/Mono.framework/Versions/Current/Commands

So /usr/local/bin is no longer used...

Original

Newer versions of mono comply to the "El Capitan" requirements of not installing anything into /usr/bin and thus now /usr/local/bin is used. I am not sure which mono 4.x release that started in...

But I would assume that you do not have /usr/local/bin in your path(?), try:

export PATH=/usr/local/bin:${PATH}
which mono
which mcs

In my case, I have 4.2.0 installed:

$ which mono
/usr/local/bin/mono
$ which mcs
/usr/local/bin/mcs
$ mono --version
Mono JIT compiler version 4.2.0 (explicit/2701b19 Mon Aug 31 09:57:28 EDT 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
$ cat `which mcs`
#!/bin/sh
export PATH=$PATH:/Library/Frameworks/Mono.framework/Versions/4.2.0/bin
export PKG_CONFIG_PATH=/Library/Frameworks/Mono.framework/External/pkgconfig:/Library/Frameworks/Mono.framework/Versions/4.2.0/lib/pkgconfig:/Library/Frameworks/Mono.framework/Versions/4.2.0/share/pkgconfig:$PKG_CONFIG_PATH
exec /Library/Frameworks/Mono.framework/Versions/4.2.0/bin/mono $MONO_OPTIONS /Library/Frameworks/Mono.framework/Versions/4.2.0/lib/mono/4.5/mcs.exe "$@"

Solution 2

In OS X El Capitan, run the following in Terminal to support mono command

export PATH=/Library/Frameworks/Mono.framework/Versions/Current/bin/:${PATH}

Solution 3

It is better to use the next export:

export PATH=$PATH:/Library/Frameworks/Mono.framework/Versions/Current/bin/

  1. You don't modify the previous order of PATH (It's very important!!)
  2. You will use the current version (when update the version it isn't necessary to change the variable PATH)

Another option (best option) is to include a new line at the end of the file /etc/paths with the content: /Library/Frameworks/Mono.framework/Versions/Current/bin

In this case, the path will be available for all users on the system.

Solution 4

After the first installation of Mono Framework using brew cask I found out that brew itself offers Mono (!)

I uninstalled Mono first.

$ brew cask uninstall mono-mdk

And installed it using brew install mono and removed all the configuration changes in ~/.zshrc.

Looks like it's much nicer:

$ type mono
mono is /usr/local/bin/mono

$ mono --version
Mono JIT compiler version 4.6.2 (Stable 4.6.2.7/08fd525 Tue Nov 22 22:05:18 GMT 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           normal
    SIGSEGV:       altstack
    Notification:  kqueue
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug
    LLVM:          supported, not enabled.
    GC:            sgen

I first used brew cask to install Mono Framework and had to add /Library/Frameworks/Mono.framework/Home/bin to PATH environment variable.

$ brew cask info mono-mdk
mono-mdk: 4.6.2.7
http://www.mono-project.com/
Not installed
From: https://github.com/caskroom/homebrew-cask/blob/master/Casks/mono-mdk.rb
==> Name
Mono
==> Artifacts
MonoFramework-MDK-4.6.2.7.macos10.xamarin.universal.pkg (pkg)
➜  kafunk git:(master) brew cask install mono-mdk
==> Downloading https://download.mono-project.com/archive/4.6.2/macos-10-universal/MonoFramework-MDK-4.6.2.7.macos10.xamarin.universal.pkg
######################################################################## 100,0%
==> Verifying checksum for Cask mono-mdk
==> Running installer for mono-mdk; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
==> installer: Package name is Mono Framework
==> installer: Installing at base path /
==> installer: The install was successful.
🍺  mono-mdk was successfully installed!

Since I use oh-my-zsh I defined MONO_HOME in ~/.zshrc and adjusted PATH accordingly:

export MONO_HOME=/Library/Frameworks/Mono.framework/Home
export PATH=$MONO_HOME/bin:$PATH

With that mono is available:

$ mono --version
Mono JIT compiler version 4.6.2 (mono-4.6.0-branch/08fd525 Thu Nov 10 20:28:28 EST 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           normal
    SIGSEGV:       altstack
    Notification:  kqueue
    Architecture:  x86
    Disabled:      none
    Misc:          softdebug
    LLVM:          yes(3.6.0svn-mono-master/8b1520c)
    GC:            sgen

Solution 5

I've been watching this page because I too had problems with installing Mono (for the first time) on El Capitan. I found the framework was installed but the commands were not put into the /usr/local/bin. Symlinking them didn't seem to work because I would get errors when trying to use the mono command and it was looking for libraries in the wrong place.

What I finally found worked (by trial and error) was setting $PATH to the Mono framework using the command in terminal:

export PATH=/Library/Frameworks/Mono.framework/Versions/4.2.0/bin/:${PATH}

Since I'm not a programmer or coder (at least not for a long time and never on OS X), this allowed me to run Duplicati using mono (which was why I wanted it in the first place), but I'm not sure if this is the correct way to solve this or even if this should be done at all. Anyone with actual programming experience to comment or clarify?

Share:
75,474
Kevin Mack
Author by

Kevin Mack

I specialize in working with Unreal Engine for games, film production, and VR.

Updated on July 05, 2022

Comments

  • Kevin Mack
    Kevin Mack almost 2 years

    I'm trying to get a Mono install running on a mac (OS X version 10.10.5), and while the install states that it's completed successfully, I'm not able to call mono from the terminal.

    To install it, I ran uninstallMono.sh as root to ensure we didn't have any leftover cruft, then ran MonoFramework-MDK-4.0.4.1.macos10.xamarin.x86.pkg. The installer appeared to complete successfully, but an attempt to call mono returns

    -bash: mono: command not found

    The mono framework does appear to be installed:

    Lees-Mac-Pro:Downloads kevinmack$ cd /Volumes/Macintosh\ HD/Library/Frameworks/
    Lees-Mac-Pro:Frameworks kevinmack$ ls -l
    total 32
    lrwxr-xr-x  1 root  wheel   71 Jan 20  2015 AEProfiling.framework -> ../../Applications/Motion.app/Contents/Frameworks/AEProfiling.framework
    lrwxr-xr-x  1 root  wheel   74 Jan 20  2015 AERegistration.framework -> ../../Applications/Motion.app/Contents/Frameworks/AERegistration.framework
    lrwxr-xr-x  1 root  wheel   74 Jan 20  2015 AudioMixEngine.framework -> ../../Applications/Motion.app/Contents/Frameworks/AudioMixEngine.framework
    drwxr-xr-x  8 root  admin  272 Sep 12 11:24 Mono.framework
    lrwxr-xr-x  1 root  wheel   60 Sep  9 22:16 NyxAudioAnalysis.framework -> /System/Library/PrivateFrameworks/NyxAudioAnalysis.framework
    drwxr-xr-x  5 root  wheel  170 Jan 20  2015 PluginManager.framework
    drwxr-xr-x  8 root  wheel  272 Sep  9 22:19 iTunesLibrary.framework
    

    ...but it isn't present in /usr/bin and attempting to find its executable using which mono returns nothing.

  • Kevin Mack
    Kevin Mack over 8 years
    This turned out to be pretty much right. usr/local/bin did not exist at all on my machine. Creating it and calling chmod 777 on usr/local, then re-installing mono took care of it. Previously, mono was attempting to install to usr/local/bin, and failing silently when it couldn't find the target directory. Thanks!
  • NovaJoe
    NovaJoe over 8 years
    There should just be a folder called "Current" that will point to your most current version instead of specifying 4.2.0 specifically. /Library/Frameworks/Mono.framework/Versions/Current/bin Right?
  • SushiHangover
    SushiHangover over 8 years
    Correct, the /Library/Frameworks/Mono.framework/Versions/Current is just a sym-link to the latest version in the Mono framework. Various install scripts actually assign the 'versioned path' directly
  • zanedp
    zanedp over 7 years
    If you don't want to have to type that every time you open Terminal, then add that line to .bash_profile in your home directory. That assumes you're still using bash, and if you're changed your shell, then you already know enough to figure out how to set up your new shell.
  • Nathan Moinvaziri
    Nathan Moinvaziri over 7 years
    We were able to get it to work by creating a symbolic link to the mono command. ln -s /Library/Frameworks/Mono.framework/Versions/Current/bin/mono /usr/local/bin/mono
  • Ben Kane
    Ben Kane over 6 years
    Thanks for this answer. This helped me find what was modifying my $PATH outside my .zshrc and any sourced files.
  • Aaron Franke
    Aaron Franke over 6 years
    So the full path to mono is /Library/Frameworks/Mono.framework/Versions/Current/bin/mono‌​, correct?
  • james-see
    james-see about 6 years
    This worked perfectly for me, I also use oh-my-zsh. I would add to make sure to source ~/.zshrc to get the updated commands to stick.
  • Charles Jaimet
    Charles Jaimet about 6 years
    And still valid a year later in April 2018. Adding to .bash_profile is the way to go.
  • Qix - MONICA WAS MISTREATED
    Qix - MONICA WAS MISTREATED over 5 years
    This is what fixed it. For some reason, /etc/paths.d wasn't being used by anything on my system so the mono-commands entry that was added was being ignored. This fixed everything for me, including Unity intellisense/autocompletion not working Visual Studio Code. Amazingly, the brew version is very much up to date. Thanks!
  • iltaf khalid
    iltaf khalid over 5 years
    I have Mono 5.10 installed, works perfect in command line but I have written a Java application which runs on Mac and is using Mono but it gives me error to: Install Mono Framework. I have added Mono's commands and bin folder to path but seems like Mono isnt accesible outside terminal.
  • iltaf khalid
    iltaf khalid over 5 years
    The Java application (jar) is able to find and run Mono if run via Terminal but doesnt find Mono (csc to be specific to compile a script) if run outside Terminal by double-clicking.
  • SushiHangover
    SushiHangover over 5 years
    @iltafkhalid There is a large difference in how the "environment" is defined when running an app via macOS Finder, ask a new question with what you are doing and issue.