Feature image for the article about how to install the Lazarus IDE on Linux

How to install the Lazarus IDE on Linux

Interested in developing a graphical user interface (GUI) application for Linux? Consider Lazarus as the integrated development environment (IDE) of choice. This article shows you how to install the Lazarus IDE on popular Linux distributions, including: Ubuntu, Debian, Fedora and openSUSE. Lazarus, with its wealth of included components, enables you to quickly design and build attractive looking GUI applications on Linux.

Background

In my opinion, Lazarus is an amazing integrated development environment (IDE) for creating graphical user interface (GUI) applications for Linux. With its graphical and intuitive form designer, you can quickly whip together a GUI. Lazarus ships with hundreds of components and even more are available from third parties. Think of these components as reusable building blocks and libraries, both graphical and non-graphical. Lazarus is open source, well maintained and has an active and friendly community.

True strengths of the Lazarus IDE

These are all great features, but there is even more. Its true strengths lies in the fact that:

  1. With Lazarus you can target different user interface widgets sets. With the flip of a switch (macro LCLWidgetType to be exact), you can build your Linux application based on the GTK2 interface or the QT5 interface.
  2. Lazarus is cross-platform. You can develop an application on and for Linux. Next, you can open and build the same project in Lazarus on Windows or macOS and voilà, it runs.

Especially this first part is what sets Lazarus apart from other GUI application development tools. Both wxWidgets and Qt enable you to develop cross-platform, but you cannot switch to a different user interface widget set. This can have a negative impact in case they decide on changing the licensing terms (looking at you, Qt).

Object Pascal programming language

Why don’t more developers build their GUI applications with Lazarus? Probably because you need to use the Object Pascal programming language. Object Pascal is an elegant, powerful and fairly easy to learn object-oriented programming language. It’s what C# borrowed its DNA from. Yet, not everyone is willing to go through the effort to learn it. I can highly recommend it though, especially if you have an interest in developing cross-platform GUI applications.

This is where wxWidgets and Qt offer more options. Bindings exists such that you can program wxWidgets and Qt applications in different programming languages, such as C, C++ and Python. The difficulty of Object Pascal lies somewhere between C and Python. Unfortunately, it doesn’t share the popularity that these two languages offer. At the time of this writing, Object Pascal’s popularity sits comfortable in the top 20 of the TIOBE index. Above popular new languages such as Go and Rust, but way below C, C++ and Python.

Screenshot of the TIOBE index of June 2021, highlighting the popularity of the Object Pascal programming language.

Examples of popular GUI applications developed with Lazarus

Who uses Lazarus for developing their GUI applications? Two popular applications come to mind:

Personally, I use Double Commander on a daily basis. It’s my go to file manager on Linux. If you are interested in giving it a try, refer to the article about getting started with Double Commander.

Support of Lazarus in Linux distributions

All popular Linux distributions consider Lazarus a first class citizen. It is readily available in the package manager of: Ubuntu, Debian, Fedora and openSUSE. Furthermore, it is relatively easy to build DEB and RPM packages of Lazarus based applications; A prerequisite to request your Lazarus based application for inclusion in the package repositories of these Linux distributions.

In this article you’ll learn how to install the Lazarus IDE on Linux. Specifically, I’ll present instructions for installing the Lazarus IDE on Ubuntu, Debian, Fedora and openSUSE. By default, the Lazarus IDE on Linux builds your GUI application based on the GTK2 widget set. The installation instructions are such, that everything is ready to build your GUI based applications, based on the QT5 widget set as well. How to actually switch the widget set is outside the scope of this article, but I’ll probably cover this in a future article. To get a head start with this, perform a quick web search for the terms “lclwidgettype qt5”.

What do you need

To follow along with the presented installation instructions of the Lazarus IDE, all you really need is an Ubuntu, Debian, Fedora or openSUSE based Linux system with desktop environment. You can use whichever desktop environment you prefer. If you don’t yet want to install Lazarus on your Linux daily driver system, consider firing up a virtual machine. To quickly get one up-and-running, refer to the article about how to install Ubuntu Desktop 20.04 LTS in VirtualBox.

Install the Lazarus IDE on Ubuntu, Debian or your Raspberry PI

Both Ubuntu and the Raspberry PI operating system derive from Debian, and they all use the apt package manager. As such, the installation instructions for the Lazarus IDE on Ubuntu and the Raspberry PI operating system, are exactly the same as for Debian. As always, start with an up-to-date system, before installing new software. Open a terminal and run:

  • sudo apt update
  • sudo apt upgrade

Next, run the following command to install Lazarus on your Ubuntu, Debian or Raspberry PI OS based Linux system:

  • sudo apt install make gdb fpc fpc-source lazarus lcl-qt5
Terminal screenshot that shows you how to install the Lazarus IDE on Ubuntu Linux. The same command can be used for installing the Lazarus IDE on Debian and even the Raspberry PI operating system.

Bonus for those running the KDE or LXQt desktop environment

Remember that I mentioned that you can choose to either target the GTK2 or QT5 widget set for your Lazarus GUI application? Well, since the Lazarus IDE is developed and built with Lazarus too, the same holds true for the Lazarus IDE itself. The Debian Lazarus packaging team even went as far as offering a QT5 version of the Lazarus IDE in their online package repository. If you’re running the KDE or LXQt desktop environment, you probably prefer QT5 based applications over GTK2 ones. Therefore, you could opt to install the QT5 version of the Lazarus IDE:

  • sudo apt install make gdb fpc fpc-source lazarus-ide-qt5 lcl-gtk2 lcl-qt5

Install the Lazarus IDE on Fedora

The procedure for installing the Lazarus IDE on Fedora is quite similar to Debian and Ubuntu. The package names are just slightly different. Start by updating your system, as recommended before installing new software:

  • sudo dnf check-update
  • sudo dnf upgrade

Continue with the actual installation of the Lazarus IDE on Fedora, by running this command:

  • sudo dnf install make gdb fpc fpc-src lazarus qt5pas-devel
Terminal screenshot that shows you how to install the Lazarus IDE on Fedora Linux.

Install the Lazarus IDE on openSUSE

Before installing the Lazarus IDE on openSUSE, update your system first. The procedure differs slightly between the fixed Leap release and the rolling Tumbleweed release.

To update your openSUSE Leap system, open a terminal and run these two commands:

  • sudo zypper refresh
  • sudo zypper update

For openSUSE Tumbleweed, the last command needs to be dist-upgrade:

  • sudo zypper refresh
  • sudo zypper dist-upgrade

Once you completed updating the installed package on your openSUSE Linux system, install of the Lazarus IDE by running command:

  • sudo zypper install make gdb fpc fpc-src lazarus libQt5Pas-devel libqt5-qtbase-devel
Terminal screenshot that shows you how to install the Lazarus IDE on openSUSE Leap and Tumbleweed.

Running the Lazarus IDE on Linux for the first time

With the Lazarus IDE installed on your Linux system, let’s take it for a spin. Locate the Lazarus shortcut in your application launcher and start it:

Screenshot that shows you how to start the Lazarus IDE, after installing it on your Linux system.

The first time your run Lazarus, it presents you with a configuration dialog. We installed all the necessary packages, so all is good and you can continue by clicking the Start IDE button.

Screenshot of the Lazarus IDE configuration dialog. This one shows up the first time you start the Lazarus IDE. click the "Start IDE" button to proceed.

Personally, I’m not the biggest fan of the default syntax highlighting colors, so I always switch it to Delphi mode. This is of course subjective and optional. To make this change, select ToolsOptions… from the main menu. On the IDE Options dialog, go to category Editor → DisplayColors. Next, select Delphi as you can see in this screenshot:

Screenshot of the Lazarus IDE options dialog. It highlights how to change the syntax highlighting color screen of the text editor.

Create a Hello World GUI application in Lazarus on Linux

With the Lazarus IDE installed, configured and running on your Linux system, let’s continue its introduction. Together, we’ll build a basic Hello World! GUI application. Lazarus automatically creates a new empty project for you, after starting it for the first time.

Build the user interface

Locate the empty window with title Form1. Let’s place an edit box and a button on Form1:

  1. From the Standard component palette, select the edit box. Next, click on Form1 where you want to place the edit box.
  2. Repeat these steps, but this time for the button. Place the button underneath the edit box on Form1.
Screenshot explaining how to add components to Form1, to create the user interface of the "Hello World!" example GUI application.

Feel free to resize Form1, the edit box and the button to your liking. As a next step we’ll add some code for changing the text in the edit box, after the user pressed the button.

Implement the button’s event handler

Double-click the button on Form1. This automatically creates the Button1Click event handler for you. Inside the event handler, we can add code to change the text in the edit box:

  • Edit1.Text := 'Hello World!';
Editor screenshot that shows you how and where to implement the button's click event handler.

Run your GUI application by starting a debug session

After implementing the event handler, we can build and run our GUI application, to verify that it works. Click the green play button on the toolbar. Alternatively, you can select Run → Run from the main menu or just hit the F9 key on your keyboard. Once the build operation completes, Lazarus automatically starts a debug session and launches our GUI application. Click the button to see if the text in the edit box changed, as expected:

Screenshot that shows what the "Hello World!" example GUI application looks like, when you run it.

If you close the Form1 window, it automatically exits the program and stops the debug session. The first time you stop a debug session by closing the program, Lazarus presents you with an Execution stopped dialog. Personally, I don’t need to see this notification every time, so I opted to click the Do not show this message again button on this dialog:

Screenshot of the Execution stopped dialog that pops up the first time you close your application and stop its debug session. Simply click the "Do not show this message again" button to prevent the dialog from showing up again.

That’s it! All that is left to do, is save your project. You can do this by selecting File → Save All from the main menu. Select the location and project filename of your preference. The next time you build and run your GUI application, Lazarus stores its executable in the same directory:

File manager screenshot that show you where the Lazarus IDE stores the executable of your GUI application.

Wrap up

In this article you learned how to install the Lazarus IDE on your Linux system. Detailed Lazarus IDE installation instructions were presented for Ubuntu, Debian, Fedora and openSUSE. As an introduction to using the Lazarus IDE, we built a basic Hello World! GUI application.

Besides being a rapid application development tool for GUI applications, the main strengths of Lazarus comes from:

  • Being cross-platform. An application developed under Linux will build and run on Windows and macOS as well. Typically without any or just minor modifications.
  • Supporting multiple widgets sets. For Linux this means that you can build both a GTK2 and a QT5 version of your GUI application.

Developing in Lazarus, does require you to code in the Object Pascal programming language. This might be its biggest hurdle. In my opinion the benefits of Lazarus outweigh this restriction of having to develop in Object Pascal. Although I’m biased. I started programming with Basic and Pascal back in the nineties.

Even though the Object Pascal programming language lost its popularity compared to the millennium change, it’s still an elegant, powerful and beginner-friendly programming language. Experienced software developers can pick it up quickly. For newbies, it’s a great first programming language to learn. Once you understand Object Pascal, making the move to another programming language such as C, C#, C++, Java and/or Python will be fairly straightforward.

Not a fan of the multiple window user interface of the Lazarus IDE? Have a look at this article:

PragmaticLinux

Long term Linux enthusiast, open source software developer and technical writer.

View all posts by PragmaticLinux →