post

Installing Free Pascal in Ubuntu

Pascal programming language is one of the commonly used language for beginners in programming. It is because Pascal has simple, structured, and clean syntax, especially when compared to that of C++.

Linux is a good operating system for competitive programmers and application developers. Personally, I always use Ubuntu, a famous Linux distribution, to create programs. The good news is that Free Pascal is included in Ubuntu repository as the standard Pascal compiler.

Here is how I install and optimize Free Pascal in Ubuntu.

Installing Compiler and IDE

Free Pascal compiler is included in Ubuntu repository as fp-compiler package. Therefore, to install the compiler, you have to install fp-compiler, by running this command in a terminal.

$ sudo apt-get install fp-compiler

Type your root password and wait until the installation finishes. You are now able to compile Pascal source code files (.pas), for example, by running

$ fpc file.pas

to compile a source code named file.pas in the current directory.

You can create Pascal files in any text editors. However, if you prefer to develop with Free Pascal IDE (integrated development environment), you can install the fp-ide package.

$ sudo apt-get install fp-ide

To launch the IDE, run

$ fp

Your terminal will turn into the legendary Free Pascal’s blue editor. You may receive a Debian bug warning depending on your Ubuntu version, but you can simply ignore it.

Integrating into GNOME Menu

Because Free Pascal is a terminal-based program, it is not available in GNOME menu. However, you can easily add a launcher menu to it. Here is how I add Free Pascal to GNOME menu.

    • Right-click GNOME menu (usually located on the upper right corner of your screen), and then click Edit Menus.
    • Select Programming submenu.
    • Click New Item.
    • Enter these details:
      • Type: Application
      • Name: Free Pascal
      • Command:
        gnome-terminal --title="Free Pascal" --geometry=80x40 --hide-menubar -e fp
    • Click OK.

Done! Now you can run Free Pascal IDE by selecting Applications -> Programming -> Free Pascal from GNOME menu. You don’t have to run it manually from the terminal again.

Installing Documentation

By default, Free Pascal documentation is not included in the previous installations. You can add it by installing fp-docs package.

$ sudo apt-get install fp-docs

The documentation files will be added to /usr/share/doc/fp-docs. It can be integrated into Free Pascal IDE, by following these steps.

  • Select Help -> Files.
  • Click New.
  • Select the file /usr/share/doc/fp-docs/fpctoc.html.
  • Click Open.
  • Wait for the indexing to finish.

After that, the documentation will be available under the menu Help.

Enjoy coding or developing Pascal programs in Ubuntu!

About Ashar Fuadi

Ashar Fuadi is a competitive programmer from University of Indonesia. He loves to code, especially for TopCoder SRM, Codeforces, and ICPC.
Follow Ashar on Google+ and Twitter.

Comments

  1. i can’t see the blue editor of free pascal. I tried to type “fp”, but the response is “shell: command not found”. what’s wrong??

    • Hello hanif,

      Try typing “fp” and press tab. You should get other suggestions. In my Ubuntu 12.04, the available option is “fp-2.4.4”.

  2. Hi fushar
    your instructions are great, but I can only run fp from my server. Other users don’t see it on application menu.
    How can I install for everyone?
    Thanx

  3. i want to learn programing languages…from where i should start?

  4. Dear fushar,
    how can i install the free pascal debugger?
    I want to install full Free Pascal IDE. Is there any other component i should install separately?

  5. Ashar Fuadi says:

    Hi Riza,

    I guess you should install GNU’s gdb. See this for more reference: http://www.freepascal.org/docs-html/user/userch10.html

  6. when there was a Pascal source error, it used to display the window “Compiler Messages.” Now, Compiler Messages does not display automatically and Window-List does list “Compiler Messages(2)” but will not allow Show.
    any one to help me??
    thanks

  7. Monika Schrenk says:

    Hi,
    I followed your instruction to install the fpc compiler with $ sudo apt-get install fp-compiler and it worked – thanks a lot!!
    but when I compile a .pas file with geany there is a message saying:
    /usr/bin/ld: warning: link.res contains output sections; did you forget -T?
    nevertheless I can compile and run .pas files without further problems.
    Do you know why this message is coming up and how to fix it?
    thanks

  8. George Kinal says:

    I am having the same problem as John (May 28). For about a day I was getting the compiler error message window, then it disappeared. That is in a Linux Mint installation. Works correctly in another installation in Ubuntu 10.

  9. Thank you A lot!!! It works 🙂

  10. Paulino says:

    Hello Fushar,

    Thank you for this instructions. I had the same problem as Hanif, I’m also using Ubuntu 12.04, and couldn’t start the IDE wit fp, but as you proposed, fp-2.4.4 worked fine.

  11. Red Baron says:

    Just so you know you need to run the FP IDE with sudo just this once when you add the doc files unless you want the keyword-thingie to be created in the user’s home directory, which will make it unusable by other users on the system (if any). By default the FP IDE creates some addition files in the folder where the html doc files are stored, which is /usr/share/doc/fp-docs/X.Y.Z with X.Y.Z being your FP IDE version.

  12. willy2nd says:

    Ashar – I am unable to install the documentation files. I downloaded them, but then I am unsure of your directions to integrate them. Please be very specific. As in WHERE do I select Help-> Files?

    Thank you

    • Ashar Fuadi says:

      Hi, you don’t have to download them; just install as instructed. You then select Help->Files in Free Pascal itself.

  13. Thanks..works well in 14.04

  14. Thank you.

  15. i have install it, i wrote a small program, the compile is successful and when i go to run it i get the message
    /bin/sh: 1: /media/kostas/……(path): permission denied

Speak Your Mind

*