Installing SWI-Prolog
SWI-Prolog is the most widely used, actively maintained, open-source Prolog implementation, originally developed by Jan Wielemaker at the University of Amsterdam and now maintained by a broad open-source community. It ships with a REPL (the ?- toplevel), a module system, and libraries for constraint logic programming, web servers, and semantic web reasoning, making it the standard choice for both learning and production Prolog development.
Cricket analogy: Choosing SWI-Prolog over lesser-maintained forks is like a franchise picking a proven all-format player such as Virat Kohli for a new team build rather than an unproven rookie — you get a stable, battle-tested tool with a strong track record.
Installing on Windows, macOS, and Linux
On Windows and macOS, the simplest path is downloading the official installer from swi-prolog.org, which bundles the SWI-Prolog runtime, the swipl executable, and the graphical SWI-Prolog IDE. On Linux, most distributions offer SWI-Prolog through their package manager — for example, sudo apt install swi-prolog on Debian/Ubuntu, or sudo dnf install pl on Fedora — and Ubuntu users specifically should add the official PPA (ppa:swi-prolog/stable) first to get the most current version.
Cricket analogy: Choosing between the official installer and a package manager is like a fan deciding between buying an official BCCI-licensed jersey from the team store versus a roadside vendor's copy — both might work, but the official channel guarantees the current season's correct version.
Verifying the Installation
After installation, open a terminal and run swipl to launch the interactive top-level; a correct install prints the SWI-Prolog version banner and drops you at the ?- prompt, where typing a simple query like ?- X is 2 + 2. should immediately return X = 4. You can exit the REPL at any time with halt. or Ctrl+D, and running swipl --version from the command line (outside the REPL) is a quick way to confirm the installed version without entering interactive mode.
Cricket analogy: Running swipl --version is like checking a bat's certification sticker before a match — a quick, low-stakes check that confirms everything meets spec before you start playing for real, the way X is 2 + 2. sanity-checks the engine.
# Debian/Ubuntu
sudo apt-add-repository ppa:swi-prolog/stable
sudo apt update
sudo apt install swi-prolog
# macOS (Homebrew)
brew install swi-prolog
# verify installation
swipl --versionSWI-Prolog includes SWISH (swish.swi-prolog.org), a free browser-based Prolog environment that requires no installation at all — useful for trying short snippets or working through early exercises before installing anything locally.
On Ubuntu, the swi-prolog package available in the default 'universe' repository can lag several versions behind the current release; add the official ppa:swi-prolog/stable PPA before installing if you need recent features like the newer CLP(FD) constraint library or updated string-handling predicates.
- SWI-Prolog is the most widely used, actively maintained open-source Prolog implementation.
- Windows and macOS users should download the official installer from swi-prolog.org.
- Linux users can install via package managers, e.g. sudo apt install swi-prolog on Debian/Ubuntu.
- Add the ppa:swi-prolog/stable PPA on Ubuntu to avoid an outdated 'universe' repository package.
- Launch the interactive top-level by running swipl in a terminal, reaching the ?- prompt.
- Verify the install with a query like ?- X is 2 + 2. or the command swipl --version.
- SWISH offers a no-install, browser-based Prolog environment for quick experimentation.
Practice what you learned
1. Which command starts the interactive SWI-Prolog top-level (REPL) after installation?
2. On Ubuntu, why might you add the ppa:swi-prolog/stable repository before installing?
3. What does typing halt. do at the ?- prompt?
4. What is SWISH?
5. Which command checks the installed SWI-Prolog version without entering the interactive REPL?
Was this page helpful?
You May Also Like
What Is Prolog?
An introduction to Prolog as a declarative, logic-based programming language built on facts, rules, and queries resolved through unification and backtracking.
Your First Prolog Program
A hands-on walkthrough of writing a family.pl file, loading it into SWI-Prolog, and querying it interactively with backtracking.
Prolog Syntax and Terms
A tour of Prolog's core data representation: atoms, numbers, variables, compound terms, and the [Head|Tail] list notation.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics