Running prolog on a mac
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:
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 theContents/MacOS
directory inside it to your system path (for example, assuming that you copied the SWI-Prolog application to your applications folder, doexport PATH=/Applications/SWI-Prolog.app/Contents/MacOS:$PATH
in your shell configuration file).Using MacPorts. Assuming it's installed and up-to-date, simply type either
sudo port install swi-prolog
for the stable version orsudo port install swi-prolog-devel
for the development version. Replacesudo port install
bysudo 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. Typeecho $PATH
in aTerminal
window to check.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.
Admin
Updated on June 20, 2020Comments
-
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 over 9 yearsI 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 over 9 yearsCall the predicate
pwd/0
to check the current directory. You can always change it by calling thecd/1
predicate. Or give a relative or absolute file path when consulting a file. -
Tomas Mikula about 9 yearsAlso, I first needed to
brew tap homebrew/x11
. -
Andreas Dolk almost 8 yearsBecause of some changes on homebrews side, this doesn't work anymore. See my answer.
-
Andreas Dolk almost 8 yearsI've removed the 'brew tap' command because it's not necessary anymore, homebrew changed the location of the formula.
-
ampersands over 7 yearsI get Error: No available formula for swi-prolog. Even after first running
brew tap homebrew/x11
-
any about 7 yearsI want the older version of swi-prolog, what should I do?
-
Nameishi over 6 yearsI used this command, It downloaded and I get the Welcome prompt but how do I create files?