Quick Start
Free Pascal (FPC) is a versatile, open-source compiler for the Pascal language as well as Object Pascal and provides a comprehensive run-time library. It is highly compatible with Delphi and Turbo Pascal dialects. The compiler is primarily used from the command line, but it can also be used with a variety of integrated development environments (IDEs) and other development tools.
This page provides a quick start to Free Pascal. It shows how to install the compiler using a package manager, create a simple Pascal program, compile and run it, and introduces some of the language features you will use most often.
Installation
The easiest way to install Free Pascal is to use your operating system’s package manager.
To install the latest release v3.2.2, select the tab for your computer’s operating system below, then follow its installation instructions.
# Ubuntu / Debian
sudo apt update && sudo apt install -y fpc
# Fedora / RHEL
sudo dnf install -y fpc
# Arch Linux
sudo pacman -S fpc
# openSUSE
sudo zypper install fpcVerification
After installation, open a new terminal window and verify:
fpc -iVIf successful, the terminal will display your installed Free Pascal version (e.g., 3.2.2).
The advantage of using your operating system’s package manager is simplicity and integration with the system. You can install, update, and uninstall FPC using the same mechanism they already use for other software.
Alternatively, you can download the official packages matching your system and then follow the installation instructions.
Your first program
Create a source file named hello.pas in a text editor:
program Hello;
begin
WriteLn('Hello, Free Pascal!');
end.- Pascal source files conventionally use the
.pasextension. - Pascal is case-insensitive (
WriteLn,writeln, andWRITELNare identical). - Every executable program file begins with
program <Name>;. - Code blocks start with
beginand end withend.. Note the final period (.). - Individual statements end with a semicolon (
;).
Compile the source code and run the program:
Compile the source code
In your terminal, navigate to the folder containing hello.pas and run:
fpc hello.pasThe compiler generates a standalone native executable in the same directory (hello on Linux/macOS or hello.exe on Windows) along with an object file hello.o.
Execute the program
Run the compiled executable directly from your shell:
# Linux / macOS
./hello
# Windows
hello.exeThe output
Hello, Free Pascal!Basic syntax overview
Below is a self-contained program demonstrating standard Pascal constructs. Save this file as syntax_demo.pas:
|
|
Compile syntax_demo.pas and run:
# Compile
fpc syntax_demo.pas
# Run in Linux / macOS
./syntax_demo
# Run in Windows
syntax_demo.exeThe output:
=== Free Pascal Syntax Demo ===
Alice is currently active.
5 + 10 = 15
Counting up:
Step 1
Step 2
Step 3
Countdown:
T-minus 2
T-minus 1For a detailed description of the language and compiler, consult the Free Pascal Reference Guide.
Source files and project structure
A small Pascal program can consist of a single .pas file. Larger applications are normally divided into several source files and units.
A typical project might contain:
-
- myproject.pas
- mainunit.pas
- calculations.pas
- utils.pas ...
The main program uses the required units through its uses clause:
uses
MainUnit,
Calculations,
Utils;Free Pascal can compile projects directly from the command line, and it can also be integrated into IDEs and build systems.
Compiler options
Free Pascal provides many compiler options for controlling compilation, debugging, optimization, warnings, and the language dialect. The basic syntax for compiling a Pascal source file with options is:
fpc [options] <filename.pas>For example, to display the compiler’s help:
fpc -hCompiler options can also be specified in source code using compiler directives, for example {$mode objfpc}.
The language mode determines which Pascal language features and compatibility rules are enabled. Free Pascal supports several modes, including fpc, objfpc, delphi, and tp.
For new Free Pascal applications, objfpc is often a suitable choice when using Object Pascal features:
program Hello;
{$mode objfpc}
begin
WriteLn('Hello, world!');
end.Some frequently-used options are listed below:
| Option | Purpose | Example |
|---|---|---|
-M<mode> |
Select language syntax dialect (e.g., objfpc, delphi, tp). |
fpc -Mobjfpc main.pas |
-o<filename> |
Change the name of the executable produced to |
fpc -oApp main.pas |
-Fu<path> |
Add |
fpc -Fu./modules main.pas |
-v<opts> |
Control compiler log messages: • -vewn Show errors, warnings, notes (default) • -v0 Show errors only |
fpc -v0 main.pas |
-h |
Display a full list of all available command-line options | fpc -h |
A complete list of Command Line Options can be found here.
Recommended Development Environments
While FPC can be run directly from the command line with any text editor, dedicated environments accelerate development:
- Lazarus IDE: the official, open-source, full-featured cross-platform IDE for FPC, providing a visual GUI drag-and-drop design similar to Delphi, cross-platform UI components, and integrated debugging.
- Visual Studio Code: Install VS Code with the Pascal extension for syntax highlighting, code completion, and integrated building.
- FPC Text Mode IDE: Run
fpin your terminal to open the built-in, lightweight terminal IDE included with standard FPC installations, suitable for lightweight or headless server setups (Not available in macOS).
Continue learning
The examples on this page gives you basic information about the free pascal and gets you started. Once you are comfortable with the basics, you can explore:
- arrays and records;
- enumerated and set types;
- pointers and dynamic memory;
- strings and string handling;
- object-oriented programming;
- classes and inheritance;
- generics;
- exception handling;
- file handling;
- multithreading;
- units and packages;
- the Run-Time Library (RTL);
- the Free Component Library (FCL).
The best way to become familiar with Free Pascal is to write small programs and experiment with the language. Additional information, user contributed documentation and links can be found on the More Information page.