COBOL Programming on Linux: Installation Guide & First Program

Linux TLDR
Last Updated:
Reading time: 3 minutes

COBOL (also known as โ€œCommon Business-Oriented Languageโ€œ) is a high-level programming language that first appeared in 1959 to meet the business data processing needs of companies and organizations.

It was particularly designed for business applications and handling large-scale data processing, and despite its declining popularity, COBOL is still powering some critical business operations.

Many companies, including key players in finance, government, airlines, transportation, and various other industries, still use COBOL (but they are gradually migrating).

This article covers COBOL in Linux, including its features, drawbacks, installation process, and a guide to running your first program.

Tutorial Details

DescriptionCOBOL Programming Language
Difficulty LevelLow
Root or Sudo PrivilegesYes (for installation)
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Internet RequiredYes (for installation)

Features and Drawbacks of COBOL

The popularity of COBOL back in the day was specifically due to the following features:

  • English-like syntax makes it easily readable for non-programmers.
  • Dynamically handles data in the form of records and files, making it perfect for business data tasks.
  • Provide a powerful data description language that allows developers to define data structures, records, and fields in a clear and structured manner.
  • Offers a set of data manipulation verbs and statements for performing arithmetic operations, data transformations, and comparisons.
  • Portable across different systems and platforms, allowing businesses to migrate their applications without extensive rewriting.

Despite its intriguing features, certain issues soon emerged, leading to a decline in its popularity, followed by:

  • While adopting an English-like syntax enhances readability, itโ€™s important to note that certain features might result in verbose and complex code, particularly when handling advanced programming concepts.
  • COBOL absence of modern language features and libraries, as seen in newer languages, hinders creating advanced applications in the Linux environment.
  • Finding skilled COBOL programmers can be difficult due to its perceived outdated nature in comparison to modern languages.

Setting aside all else, letโ€™s explore how to install it on your Linux system, enabling you to execute your first COBOL program.

How to Install COBOL on Linux

COBOL is a classic programming language and is typically included in the repositories of most Linux distributions, although the package name may vary.

I would suggest you use COBOL on RHEL-based distributions such as Fedora, as it continues to offer backward compatibility.

To set it up on Linux, begin by launching your terminal. Then, run the suitable command for your distribution to update the system package database.

$ sudo apt update                                                                               #For Debian, Ubuntu, Linux Mint, etc.
$ sudo dnf update                                                                               #For RHEL, Fedora, AlmaLinux, CentOS, etc.
$ sudo pacman -Sy                                                                             #For Arch, Manjaro, EndeavourOS, etc.

After updating the package database, run one of the following commands based on your Linux distribution to start the COBOL installation process:

$ sudo apt install gnucobol                                                                 #For Debian, Ubuntu, Linux Mint, etc.
$ sudo dnf install gnucobol                                                                 #For RHEL, Fedora, AlmaLinux, CentOS, etc.
$ sudo pacman -S gnucobol                                                               #For Arch, Manjaro, EndeavourOS, etc.

After the installation is complete, you can verify if COBOL is installed by checking its version:

$ cobc --version


Checking the cobol version to ensure it properly installed

Now, letโ€™s see how you can run your first COBOL program on Linux!

Writing, Compiling, and Executing COBOL Programs

After installing COBOL on your Linux system, youโ€™re all set to write and run your first COBOL program. Simply follow these steps one by one.

Micro Focus is a software company that provides tools and solutions for modernizing and maintaining COBOL-based applications.

1. Create a new project directory, named โ€œMyCBLโ€œ, and move into it.

$ mkdir MyCBL
$ cd MyCBL

2. Now, create a file for your COBOL program, naming it โ€œhelloworld.cblโ€ with the โ€œ.cblโ€ extension.

$ vim helloworld.cbl

When you run the above command, it will open the blank file in Vim, ready to edit.

3. Inside the file, you can start writing your COBOL program. For instance, you can copy the following program, which does nothing except print a simple message to our terminal:

      *simple cobol program.
           DISPLAY 'Hello, Readers!'.
           DISPLAY 'Thanks for Supporting, LinuxTLDR!'.
           STOP RUN.

Save the file and exit the text editor.

4. Compile the program using the โ€œcobcโ€ compiler with the โ€œ-xโ€ flag to generate an executable:

$ cobc -x helloworld.cbl

5. When you โ€œlsโ€ the file content, you will find your original โ€œhelloworld.cblโ€ file, including the executable file named โ€œhelloworldโ€œ. Simply run the executable.

$ ./helloworld


Writing and running the first COBOL program on linux

Thatโ€™s it! Youโ€™ve successfully installed COBOL and written a simple COBOL program on your Linux system.

If you want to learn more (which I donโ€™t suggest if you are learning it from scratch), you can check out the old (or outdated) guides or books.

Apart from that, if you have any questions or queries regarding the topic, feel free to ask them in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.