Computing: Free Pascal Programming

Installing Lazarus/Free Pascal on CentOS.


Important note: This tutorial applies to CentOS 7 (I suppose that the RPM issue described below is the same for earlier versions, without having any idea, if, following the procedure that I use here to resolve it, the installation of Lazarus succeeds). As far as I know, the problem doesn't any longer occur with CentOS 8 with rpm-4.14.2-36.el8 update. Thus, to simplify things for yourself, you should perhaps using this latter version.
As a difference with many other Linux distributions, the CentOS repositories do not contain a Lazarus package. Thus, beside building Lazarus from source, the only possibility is to use the unspecific RPM binaries on Sourceforge. You can find the links to the 32bit and 64bit RPM releases on the Lazarus Downloads page. Please, note that it's mandatory to install the following three files (the filenames given are for Lazarus 2.2.2.0 64bit and FPC 3.2.2.1 64bit): the FPC compiler (fpc-3.2.2-1.x86_64.rpm), the Free Pascal sources (fpc-src-3.2.2-1.x86_64.rpm), and the Lazarus IDE (lazarus-2.2.2-0.x86_64.rpm). Optionally, you can also install the documentation (fpc-docs-3.2.2-1.x86_64.rpm).
Supposing the 3 files are in your Downloads folder, cd to this directory in a terminal and enter
    su
to become root (you'll be asked to enter the root password). Installation may be done using the Yum package installer. In the terminal, type:
    yum install ./fpc-3.2.2-1.x86_64.rpm
Everything seems fine: dependencies are resolved, transaction check is run, the installation size is displayed and you are asked if this is OK. But, entering "Y" to start the installation will result in the following error message (and abortion of the installation):
    ERROR: You need to update rpm to handle:
    rmplib(PayloadIsZStd) <= 5.4.18-1 is needed by fpc-3.2.2-1.x86_64
RPM error when trying to install the Free Pascal compiler
This is due to the fact that the RPMs on the Sourceforge site are build using the zstd payload, that isn't supported by CentOS 7 (which uses xy for package compression). Trying to install rpm-4.14.2-36.el8, that includes this functionality, seems not to work. So, what to do? RPM based Linux distributions include a tool called rpmrebuild, that allows to build a new RPM from an existing one, with the characteristics specified by the user. So, rebuilding the FPC RPM in a way not to use zstd compression should make it possible to install the compiler on CentOS 7. I suppose that it's not possible to do the rebuild on CentOS 7. I did it on my OpenSUSE 15 Leap. If you haven't this OS installed, you can try another one (Fedora should work, I guess), or, if you prefer to stay with the tutorial, download the OpenSUSE ISO and run the OS as Live-CD.
rpmrebuid can be installed on OpenSUSE using YaST2. This done, open a terminal, browse to the directory that contains the RPM and type the following command:
    sudo rpmrebuild -enp fpc-3.2.2-1.x86_64.rpm
sudo gives you root privileges to execute the command. e, n, and p are options for the rpmrebuild program.
rpmrebuid creates the new RPM, based on the content of a specfile, that is automatically generated by rpmrebuid itself and may then be edited by the user. The following applies to running rpmrebuid on OpenSUSE, but should be similar for other distributions. After the specfile has been generated, it opens in the default editor, that in OpenSUSE is Vi. Vi runs in the same terminal, where you launched the rebuild program, and when you'll leave the editor the rebuild process will continue.
Rebuild of the Free Pascal compiler RPM on OpenSUSE: specfile opened in Vi
Vi is nice, but if you never used it, you probably ask yourself "What the hell must I do to edit this file?" Here, all you need to know to make the necessary changes to the specfile:
  • Vi starts in edit mode. To be able to insert characters or lines, push the Insert key on the keyboard (by default, Vi is in overwrite mode). Now you can edit your text in the same way, you do with other editors. One notable exception: the Backspace key is not working in Vi; use the Delete key, if you want to erase some characters.
  • The Escape key on the keyboard allows to pass from edit mode to command mode. Keyboard input does no longer change the text in the editor, but Vi now awaits a command. To enter a command, type a colon (:) and then type the letter for the command you want to execute.
  • Just two commands, that we need to know here: :w (write) is used to save the file content, :q (quit) is used to exit the Vi editor and return to the command line.
The screenshot below shows the beginning of the specfile, opened in Vi. Here, the modifications to the specfile, that you have to make in order to create an RPM that is supported on CentOS 7:
  • Find the lines that list the requirements and remove the rpmlib(PayloadIsZStd) requirement.
  • Add the following two lines (I added them before the %define already there):
        %define _source_payload w0.gzdio
        %define _binary_payload w0.gzdio
Save the file and quit the Vi editor. The editor content is removed from the display and you return to the command line, where you are asked if you want to continue or not. Enter "y". As you can see on the screenshot further down, there are lots of warning messages displayed. I don't know if this is normal. It seems that you may safely ignore them. My new RPM was created and I succeeded without any problem to install it on CentOS 7.
The last output line of the rpmrebuild program indicates where the new RPM has been saved. The output directory will be /usr/src/packages/RPMS/x86_64 (may be SUSE specific), the file name being the same as the original RPM. The screenshot below shows the error messages that I got when doing the rebuild, followed by the indication of the new file's path. As the new file created has actually nothing to do with my OpenSUSE machine, I moved it from the location, where it was saved, to my home directory (root privileges needed to do so).
Rebuild of the Free Pascal compiler RPM on OpenSUSE: warning messages
Back on CentOS 7, we can now install the (newly created) FPC compiler RPM. Success (screenshot). The Free Pascal sources RPM and the Lazarus IDE RPM do not use zstd compression, so, you may install them from the original download files. On the other hand, if you want to install the Free Pascal documentation, you'll have to rebuild the fpc-docs-3.2.2-1.x86_64.rpm file.
Successful installation of the (rebuild) Free Pascal compiler RPM on CentOS 7
You'll find the shortcut to launch the Lazarus IDE in Applications > Programming. Startup is fast and, as it is the first time Lazarus is launched, the Configure Lazarus IDE window is displayed. As you can see on the screenshot, all components have been found!
Lazarus startup on CentOS 7: IDE configuration window
The rearrangement of the windows on the desktop works smoother and there isn't this startup delay, as I have on Ubuntu 20.04. If you open a Lazarus Project Information (.lpi) file, your are asked (as on all Linux systems) if you want to open the project or open the file as XML. To test the installation, I tried to build my RaubtierQuiz (carnivore quiz) application. Success. And running the created executable: Also OK!
Lazarus on CentOS 7: Successful build of a GUI application


If you find this text helpful, please, support me and this website by signing my guestbook.