How to Install GNU Cobol and the First Steps

🚀 Procedure for Windows, macOS, GNU/Linux and BSD.


How to Install GNU Cobol and the First Steps


GnuCOBOL (formerly known as OpenCOBOL and briefly as GNU Cobol) is a free implementation of the COBOL programming language that is part of the GNU project. GnuCOBOL translates COBOL code into C and then compiles it using the native C compiler.


How to install

Installation on Ubuntu

  1. Update the system: First, it is recommended to update the package list and the system:
sudo apt update && sudo apt upgrade
  1. Install GnuCOBOL: GnuCOBOL is available in the default Ubuntu repositories. You can install it using the following command:
sudo apt install gnucobol
  1. Verify the installation: After the installation, you can verify that GnuCOBOL was installed correctly by running:
cobc --version

This will display the version of GnuCOBOL installed.

Installation on Windows

On Windows, the installation of GnuCOBOL can be done manually or via WSL2. Manual procedure:

  1. Download GnuCOBOL: from the address: Direct to files on SourceForge

  2. Extract the ZIP: to a directory of your choice, for example, C:\gnucobol.

  3. Set the environment variables:
    • Add the GnuCOBOL bin directory to your PATH:
  4. Right-click on “This PC” or “My Computer” and select “Properties”.

  5. Click on “Advanced system settings”.

  6. In the “Advanced” tab, click on “Environment variables”.

  7. In the “System variables” section, find the Path variable and click on “Edit”.

  8. Add the path to the GnuCOBOL bin directory (e.g. C:\gnucobol\bin) to the end of the path list.

  9. Click “OK” to save the changes.

  10. Verify the installation:
    • Open the Command Prompt (CMD) and run:
cobc --version
  • This will display the version of GnuCOBOL installed.

Getting Started with GnuCOBOL

After the installation, you can test GnuCOBOL by creating a simple COBOL program. For example, create a file called hello.cbl with the following content:

NOTE: In Cobol it is important to respect these leading spaces!

      *> Meu Hello World em GnuCobol
       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLO-WORLD.
       PROCEDURE DIVISION.
           DISPLAY "Hello, World!".
           STOP RUN.

To compile and run on Ubuntu or Windows, use the following commands:

cobc -x hello.cbl
./hello

If you see any warning it may be because _FORTIFY_SOURCE is being defined somewhere in your build environment. If this is bothering you, ignore it like this: cobc -x hello.cbl 2>/dev/null.

On Windows, the command to run the program would be:

hello.exe

This should display “Hello, World!” in the terminal.

For macOS and BSD you can either use the system’s package manager or download it, just like on Windows, directly from SourceForge:

https://sourceforge.net/projects/gnucobol/files/gnucobol/3.2/


For more information, see this PDF, the Guide and the official address.


gnu cobol programming


Share


YouTube channel

Subscribe


Marcos Oliveira

Marcos Oliveira

Software developer
https://github.com/terroo