Install GnuCOBOL

If you created a VM, make sure you are running these steps as the normal user in that VM; not on the host system.

These instructions are for Pop!_OS, they should be similar for Ubuntu.

Install Build-Essential first

In Terminal, Run:

sudo apt install build-essential

This might be installed already or there might be some components that are missing. Better safe then sorry.

Get GnuCOBOL

Download the source code from GnuCOBOL

As of March 1, 2023, the current version is 3.1.2.

For that version, download: gnucobol-3.1.2.tar.xz.

If you haven't made any changes, it will be downloaded to the Downloads directory.

Extract the downloaded file

Open Files and go to the Downloads folder.

Double click on the gnucobol-3.1.2.tar.xz file.

This will open Archive Manager.

You will see "gnucobol-3.1.2". Click on the "Extract" button in the upper left hand corner.

A dialog box will open to select where to extract the file to. Extract the file to the ~/builds directory.

When it is done, close the dialog box, close Archive Manager, and close Files.

Install additional software

Open Terminal to install the following:

sudo apt install libgmp-dev
sudo apt install libdb5.3-dev
sudo apt install libncurses-dev
sudo apt install libxml2-dev
sudo apt install libcjson-dev

Configure, Make and Install

Run:

cd builds/gnucobol-3.1.2

This will take you into the gnucobol-3.1.2 directory.

Run:

./configure

A whole bunch of messages will print on the screen

At the end, there should be some messages that look like:

extended screen I/O      : ncursesw
variable file format     : 0
sequential file handler  : built-in
indexed file handler     : BDB
mathematical library     : GMP
XML library              : libxml2
JSON library             : json-c

If there are no errors, Run:

make

More messages will display, if there are no errors, Run:

make check

A suite of tests will run, at the end, you should see the results:

1082 tests behaved as expected.
4 tests were skipped

Run:

sudo make install

Then Run:

sudo ldconfig

As a quick test, Run:

cobc

You should get an error message:

cobc: error: no input files

For a better test of the install:

  1. Create a new directory
  2. Create a simple COBOL program
  3. Run it.

1: Create a new directory

In Terminal, Run:

cd
mkdir -p ~/dev/cobol/test-cobol
cd ~/dev/cobol/test-cobol
touch hello.cbl

2: Create a simple COBOL program

Open Files, go to the dev/cobol/test-cobol folder.

Double-click on hello.cbl. This will open it in Text Editor.

Copy the following code and paste it into hello.cbl:

       IDENTIFICATION DIVISION.
       PROGRAM-ID. SmallestProgram.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
            DISPLAY "Hello world"
            STOP RUN.
       END PROGRAM SmallestProgram.

and save it.

Go to Terminal, Run:

pwd

To make sure you are in the ~/dev/cobol/test-cobol directory.

Run:

cobc -x hello.cbl

If it complies correctly(no messages), Run:

./hello

It should return:

Hello world

If this works, delete the test-cobol directory (or not, your choice).