Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 36 ยท Getting Started

Setting Up Free Pascal, Lazarus and Delphi

Choose a Pascal toolchain and set it up: install Free Pascal, Lazarus or Delphi Community Edition, compile from the command line, pick a mode and fix common first-run problems.

To follow this course on your own machine you need a Pascal compiler. You have three good options, and all of them run the code in this tutorial with only small differences. This lesson helps you choose, shows how to install each one, and walks through compiling a first file by hand so you understand what the IDE does for you.

Remember that this site can show Pascal code but cannot run it. Everything installed here happens on your computer.

Choosing a toolchain

Option Cost Best for Notes
Free Pascal (FPC) Free, open source Console programs, learning the language, servers A command-line compiler plus units. Use any text editor.
Lazarus Free, open source Visual desktop apps, learning forms Includes FPC and a Delphi-like designer. Windows, Linux, macOS.
Delphi Community Edition Free for personal and small-revenue use (license terms apply) Professional Delphi work, FireMonkey Windows-only IDE, targets several platforms.

If you only want to learn the language, install Free Pascal. If you want forms and buttons later, install Lazarus, which bundles the compiler. If your job uses Delphi, install Delphi and read this course using its console application template.

Check the vendor's current license page before using Delphi Community Edition commercially; the conditions (such as a revenue limit) change over time.

Installing Free Pascal

  1. Windows. Download the installer from the Free Pascal website and run it. Keep the option that adds the compiler to your PATH. Reopen your terminal afterwards.
  2. macOS. Use the official installer package, or Homebrew (brew install fpc).
  3. Linux. Use your package manager: for example sudo apt install fp-compiler on Debian or Ubuntu, sudo dnf install fpc on Fedora.

Confirm it works:

Terminal
fpc -iV

This prints the compiler version number. If the command is not found, your PATH does not include the compiler folder yet.

Installing Lazarus

Download Lazarus for your operating system from the project's site. The installer includes a matching Free Pascal compiler, so you do not need to install FPC first. On first launch you see a source editor, an object inspector and an empty form. For console learning choose Project > New Project > Program (a simple console program), and press the green Run button.

Installing Delphi Community Edition

Register on the Embarcadero website, download the installer and follow the wizard. You need a Windows machine. After installing, create a console project with File > New > Console Application. Delphi generates a file with a program header and a {$APPTYPE CONSOLE} directive, and the Run button compiles and starts it.

Compiling by hand

Even if you use an IDE, it is worth compiling once from the terminal, because it shows what happens. Create a file hello.pas:

PASCAL
program Hello;
begin
  WriteLn('Hello from Pascal!');
end.

Then run these two commands:

Terminal
fpc hello.pas
./hello

On Windows run hello.exe. The first command compiles hello.pas and links a native executable. FPC prints its banner, some Compiling and Linking lines, and a final count of lines compiled. The second command runs the program. No virtual machine or runtime is needed.

flowchart LR
    S["hello.pas<br/>source"] --> C["fpc compiler"]
    C --> O["hello.o<br/>object file"]
    O --> L["linker"]
    L --> E["hello / hello.exe<br/>executable"]

Figure: the compile-and-link pipeline. Units you use are compiled to .ppu files and reused.

The compiler also leaves hello.o and sometimes a .ppu file next to your source. They are build products you can delete.

Useful compiler options

Option Meaning
-Mobjfpc Use Object Pascal mode (also set by {$mode objfpc} in a file)
-Mdelphi Use Delphi-compatible mode
-O2 Optimize the output
-g Add debug information
-Fu<dir> Add a folder to search for units
-FE<dir> Put the finished executable in a folder
-vw Show warnings (hints and notes are -vh and -vn)

A typical development command is fpc -Mobjfpc -g hello.pas.

Modes and settings at the top of a file

Many examples in this course begin with a mode line. Without it, FPC uses its default mode, which behaves like a mix of Turbo Pascal and ISO Pascal. For modern code choose one:

PASCAL
{$mode objfpc}{$H+}
program ModeDemo;
begin
  WriteLn('Object Pascal mode with long strings');
end.

The {$H+} switch makes the plain string type a long, dynamically sized string. In Delphi mode that is already the default. You will meet the details in Booleans, Characters and Strings.

Common first-run problems

  • "Fatal: Can't find unit ...": the compiler cannot find a library; add -Fu or reinstall.
  • "Fatal: Syntax error, . expected": a missing end. or an end; at the end of the program. The last word must be end followed by a full stop.
  • A console window flashes and closes (Windows, double-clicked executable): run the program from a terminal, or end it with ReadLn; while learning.
  • The terminal shows strange characters: Windows consoles use a legacy encoding unless you set it up; plain English text works everywhere.

Stand-in: what the compiler counts

The compiler reports how many lines it compiled. This C stand-in (not Pascal) counts lines and words in a text, the same kind of work a tool does while reading your source file.

C C stand-in: counting lines and words

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which tool includes both the Free Pascal compiler and a visual form designer?

    Lazarus bundles FPC and a Delphi-like visual designer. Delphi is Windows-hosted and commercial, and fpc alone has no IDE.
  2. 2. What does the command fpc hello.pas produce?

    FPC compiles and links a native executable. No runtime or virtual machine is required to run it.
  3. 3. What does {$mode objfpc} do?

    It is a compiler directive that chooses the dialect. {$H+} is a separate switch for long strings.
  4. 4. A program fails with "Syntax error, . expected". What is the likely cause?

    A Pascal program must end with end.. The compiler expects the full stop where the main block closes.

Summary

  • Choose Free Pascal for the language, Lazarus for visual apps, Delphi for professional Windows-centric work.
  • fpc file.pas compiles and links a native executable; fpc -iV shows the version.
  • Mode directives such as {$mode objfpc}{$H+} select the dialect and string behavior.
  • Most beginner errors are a missing end. or a missing unit path.

Next: Your First Pascal Program