Skip to content
🎉 Free Pascal v3.2.4 is out! See Release Notes
Quick Start

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.

You can also try Free Pascal online in the Playground without installing anything on your computer.

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 fpc

Verification

After installation, open a new terminal window and verify:

fpc -iV

If 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:

hello.pas
program Hello;

begin
  WriteLn('Hello, Free Pascal!');
end.
  • Pascal source files conventionally use the .pas extension.
  • Pascal is case-insensitive (WriteLn, writeln, and WRITELN are identical).
  • Every executable program file begins with program <Name>;.
  • Code blocks start with begin and end with end.. 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.pas

The 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.exe

The output

Hello, Free Pascal!

Basic syntax overview

Below is a self-contained program demonstrating standard Pascal constructs. Save this file as syntax_demo.pas:

syntax_demo.pas
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
program SyntaxDemo;

// 1. Variable Declarations
var
  UserName: String;
  UserAge: Integer;
  IsActive: Boolean;
  i: Integer;

// 2. Custom Function (returns a value)
function AddNumbers(a, b: Integer): Integer;
begin
  AddNumbers := a + b; // Assign value to function name to return it
end;

// 3. Custom Procedure (does not return a value)
procedure PrintHeader(Title: String);
begin
  WriteLn('=== ', Title, ' ===');
end;

// Main Program Logic
begin
  PrintHeader('Free Pascal Syntax Demo');

  // Value Assignments
  UserName := 'Alice';
  UserAge := 30;
  IsActive := True;

  // Conditionals
  if IsActive then
    WriteLn(UserName, ' is currently active.')
  else
    WriteLn(UserName, ' is inactive.');

  // Function Call & Output
  WriteLn('5 + 10 = ', AddNumbers(5, 10));

  // For Loop
  WriteLn('Counting up:');
  for i := 1 to 3 do
  begin
    WriteLn('  Step ', i);
  end;

  // While Loop
  i := 2;
  WriteLn('Countdown:');
  while i > 0 do
  begin
    WriteLn('  T-minus ', i);
    i := i - 1;
  end;
end.

Compile syntax_demo.pas and run:

# Compile
fpc syntax_demo.pas

# Run in Linux / macOS
./syntax_demo

# Run in Windows
syntax_demo.exe

The 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 1

For 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 -h

Compiler 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 to unit path 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 fp in 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.