Running prolog on a mac

67,322

Solution 1

If you have Homebrew installed, you can simply run

brew install swi-prolog

from Terminal, which will build it from source in one command.

You can then run the interpreter using swipl.

Solution 2

There are three sensible ways of installing SWI-Prolog on MacOS X, in increasing order of complexity:

  1. Download the SWI-Prolog application. In this case, you just download a disk image, open it, and drag the application to your disk (e.g. to your Applications folder. You use the application as any other application by double-clicking on its icon. If you want to also use the binary inside the application bundle, add the Contents/MacOS directory inside it to your system path (for example, assuming that you copied the SWI-Prolog application to your applications folder, do export PATH=/Applications/SWI-Prolog.app/Contents/MacOS:$PATH in your shell configuration file).

  2. Using MacPorts. Assuming it's installed and up-to-date, simply type either sudo port install swi-prolog for the stable version or sudo port install swi-prolog-devel for the development version. Replace sudo port install by sudo port -u upgrade when upgrading the installed version. It you're already using MacPorts, then /opt/local/bin should already be in your system path. Type echo $PATH in a Terminal window to check.

  3. Compiling from sources. In this case, download the source archive, uncompress it, and follow the instructions in the README.MacOSX file.

Solution 3

The OSX EI Captian has this command for swi-prolog installation

brew install homebrew/x11/swi-prolog

Solution 4

If you download the SWI-Prolog application into your /Applications folder, then add this to your .bash_profile:

export PATH="/Applications/SWI-Prolog.app/Contents/MacOS:$PATH"

The swipl binary lives in that MacOS directory. (Don't forget to source ~/.bash_profile after)

Solution 5

Homebrew has moved swi-prolog to the top a few days ago and because of this, the other answers are not valid anymore. The reason for that: the swi-prolog formula was located in the x11 bottle but the x11 dependency is only optional.

As of today, to install swi-prolog with homebrew, simply do:

brew install swi-prolog

If you've installed it from the x11 bottle before, consider to uninstall an reinstall from the new location. Otherwise you might run into errors when updating/upgrading.

Share:
67,322
Admin
Author by

Admin

Updated on June 20, 2020

Comments

  • Admin
    Admin almost 4 years

    I am having the hardest trouble trying to run SWI-prolog on my Mac.

    When I type:

    /opt/bin/local/swipl
    

    I get an error saying:

    /opt/local/bin/swipl: No such file or directory
    

    When I just type "swipl" I get:

    swipl: command not found
    

    I've tried this on both terminal and XQuartz. I've even gone into

    /Applications/SWI-Prolog.app/Contents/MacOS
    

    to see if that would do anything, however the prolog "Welcome" text never appears. Quite possibly the closest I ever got it to work was when I typed "pl" when inside the MacOS folder. However I was left with my terminal doing nothing and had to use Crtl-D.

    Is there something I'm doing wrong? Did I install something incorrectly?

    I'm running on a Mac OS X 10.9.1 Mavericks. I placed the SWI-Prolog application into my application folder and I also downloaded XQuartz per recommendation by the website.

  • The Oddler
    The Oddler over 9 years
    I did the first option, and I get a window where I can put in prolog commands, with the familiar ?-. So that's good, but I'm having a hard time loading a pl file. Usually you can do [fileName]. but this doesn't work, I'm guessing because it doesn't know where to look for this file. Any idea how I fix that?
  • Paulo Moura
    Paulo Moura over 9 years
    Call the predicate pwd/0to check the current directory. You can always change it by calling the cd/1 predicate. Or give a relative or absolute file path when consulting a file.
  • Tomas Mikula
    Tomas Mikula about 9 years
    Also, I first needed to brew tap homebrew/x11.
  • Andreas Dolk
    Andreas Dolk almost 8 years
    Because of some changes on homebrews side, this doesn't work anymore. See my answer.
  • Andreas Dolk
    Andreas Dolk almost 8 years
    I've removed the 'brew tap' command because it's not necessary anymore, homebrew changed the location of the formula.
  • ampersands
    ampersands over 7 years
    I get Error: No available formula for swi-prolog. Even after first running brew tap homebrew/x11
  • any
    any about 7 years
    I want the older version of swi-prolog, what should I do?
  • Nameishi
    Nameishi over 6 years
    I used this command, It downloaded and I get the Welcome prompt but how do I create files?