Getting started with COBOL development on Fedora Linux 33


Though its popularity has waned, COBOL is still powering business critical operations within many major organizations. As the need to update, upgrade and troubleshoot these applications grows, so may the demand for anyone with COBOL development knowledge.

Fedora 33 represents an excellent platform for COBOL development.
This article will detail how to install and configure tools, as well as compile and run a COBOL program.

Installing and configuring tools

GnuCOBOL is a free and open modern compiler maintained by volunteer developers. To install, open a terminal and execute the following command:

# sudo dnf -y install gnucobol 

Once completed, execute this command to verify that GnuCOBOL is ready for work:

# cobc -v

You should see version information and build dates. Don’t worry if you see the error “no input files”. We will create a COBOL program file with the Vim text editor in the following steps.

Fedora ships with a minimal version of Vim, but it would be nice to have some of the extra features that the full version can offer (such as COBOL syntax highlighting). Run the command below to install Vim-enhanced, which will overwrite Vim-minimal:

# sudo dnf -y install vim-enhanced

Writing, Compiling, and Executing COBOL programs

At this point, you are ready to write a COBOL program. For this example, I am set up with username fedorauser and I will create a folder under my home directory to store my COBOL programs. I called mine cobolcode.

# mkdir /home/fedorauser/cobolcode
# cd /home/fedorauser/cobolcode

Now we can create and open a new file to enter our COBOL source program. I’ll call it helloworld.cbl.

# vim helloworld.cbl

You should now have the blank file open in Vim, ready to edit. This will be a simple program that does nothing except print out a message to our terminal.

Enable “insert” mode in vim by pressing the “i” key, and key in the text below. Vim will assist with placement of your code sections. This can be very helpful since every character space in a COBOL file has a purpose (it’s a digital representation of the physical cards that developers would complete and feed into the computer).

      *simple helloworld program.
           DISPLAY '##################################'.
           DISPLAY '#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#'.
           DISPLAY '#!!!!!!!!!!FEDORA RULES!!!!!!!!!!#'.
           DISPLAY '#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#'.
           DISPLAY '##################################'.
           STOP RUN.

You can now press the “ESC” key to exit insert mode, and key in “:x” to save and close the file.

Compile the program by keying in the following:

# cobc -x helloworld.cbl

It should complete quickly with return status: 0. Key in “ls” to view the contents of your current directory. You should see your original helloworld.cbl file, as well as a new file simply named helloworld.

Execute the COBOL program.

# ./helloworld

If you see your text output without errors, then you have sucessfully compiled and executed the program!

Now that we have the basics of writing, compiling, and running a COBOL program, lets try one that does something a little more interesting.

The following program will generate the Fibonacci sequence given your input. Use Vim to create a file called fib.cbl and input the text below:

      * Author: Bryan Flood
      * Date: 25/10/2018
      * Purpose: Compute Fibonacci Numbers
      * Tectonics: cobc
       01  N0             BINARY-C-LONG VALUE 0.
       01  N1             BINARY-C-LONG VALUE 1.
       01  SWAP           BINARY-C-LONG VALUE 1.
       01  RESULT         PIC Z(20)9.
       01  I              BINARY-C-LONG VALUE 0.
       01  I-MAX          BINARY-C-LONG VALUE 0.
       01  LARGEST-N      BINARY-C-LONG VALUE 92.
           PERFORM MAIN
            ACCEPT I-MAX.
            EVALUATE TRUE
              WHEN I-MAX > LARGEST-N
                 PERFORM INVALIDN
              WHEN I-MAX > 2
              WHEN I-MAX = 2
                 PERFORM CASE2
              WHEN I-MAX = 1
                 PERFORM CASE1
              WHEN I-MAX = 0
                 PERFORM CASE0
              WHEN OTHER
                 PERFORM INVALIDN
            STOP RUN.
       *>  THE CASE FOR WHEN N = 0
           MOVE N0 TO RESULT.
           DISPLAY RESULT.
      *>  THE CASE FOR WHEN N = 1
           PERFORM CASE0
           MOVE N1 TO RESULT.
           DISPLAY RESULT.
      *>  THE CASE FOR WHEN N = 2
           PERFORM CASE1
           MOVE N1 TO RESULT.
           DISPLAY RESULT.
      *>  THE CASE FOR WHEN N > 2
           PERFORM CASE1
                   ADD N0 TO N1 GIVING SWAP
                   MOVE N1 TO N0
                   MOVE SWAP TO N1
                   MOVE SWAP TO RESULT
                   DISPLAY RESULT

As before, hit the “ESC” key to exit insert mode, and key in “:x” to save and close the file.

Compile the program:

# cobc -x fib.cbl

Now execute the program:

# ./fib

The program will ask for you to input a number, and will then generate Fibonacci output based upon that number.

Further Study

There are numerous resources available on the internet to consult, however vast amounts of knowledge reside only in legacy print. Keep an eye out for vintage COBOL guides when visiting used book stores and public libraries; you may find copies of endangered manuals at a rock-bottom prices!

It is also worth noting that helpful documentation was installed on your system when you installed GnuCOBOL. You can access them with these terminal commands:

# info gnucobol
# man cobc
# cobc -h
For Developers Using Software


  1. Folkert M.

    Hi donnie,
    the last time I heard of COBOL was in the year before the millennium. There in Europe even seemingly dead COBOL programmers were resurrected, because the financial services industry was trembling before the turn of the millennium. What is your motive to deal with this extinct species again today. IBM, Siemens, Mainframes Computer, Government Agencies, Banks?

    • All of the above. Those are all examples where COBOL is still in use. I hope there will be readers interested in learning enough to keep the final critical applications online (while prioritizing a migration to replacement solutions written in a more modern technology stack!)

      • I learned BASIC on a Commodore PET in 1978 or so, few years later, I learned 6502 assembly. Still probably the most fun I had, though many others have been fun. I took COBOL at the local Technical Institute.. didn’t seem hard, just tedious.. I think the only language I like less than COBOL was IBM Mainframe assembly. Whoever designed and wrote that must have slipped past the sanity line a long time before doing so.. But.. I’d probably consider whoever did COBOL probably went with whoever. 😉 Yikes.

        donnie: By that time, someone will have written a real AI, and will have killed us all, or if one of the few dozen benevolent people in the race to write it first happens to win the race, If there’s any need at all, which seems Incredibly unlikely.. the machine could convert it to every other language available, for all possible hardware/software configurations…. every single line of COBOL code connected to the net probably translated into every other plausible language within minutes, majority of the time being net speeds and latencies and the like.. But really, it’s hard to imagine a need at all at that point.
        And as for the link… it’d probably (have been?) faster to write a quick hack script to convert the COBOL to something recent, that runs on current hardware..

  2. Baljeet Singh

    Thanks for valuable info

  3. Yamato

    Thanks for sharing this, I never gave Cobol a chance, but it’s never too late to learn something new.
    Now it’s time to hunt some good old books!

  4. leslie Satenstein

    This presentation brought back great memories of myself writing code in the 1950’s and earliy 1960’s. I was at that time a cobol biggot for IBM mainframes.
    Packed decimal was the favourite integer format for manipulation. Unfortuneatly (or fortunately) AMD and Intel processors do not directly support Packed Decimal Arithmetic.

    Yes, I wrote Cobol code more than 60 years ago. It is still a great language for business processing.

    • Angelo Geulin

      You must pass on the knowledge before the language goes extinct!

    • Ricardo Bánffy

      That’s surreal. Even the 6502 of Apple II and Atari fame had native support for BCD.

      It was buggy and useless, but it was there 😉

    • If you are interested in having a significant post-retirement payday, I hope you will keep an ear out for the news! I suspect it will not be long before another major organization finds itself with a major COBOL problem; giving you a unique position to set the price.

  5. leo sol

    so nice

  6. Jens Petersen

    Thanks for the interesting intro.

    One small suggestion: it might be better to screenshot just the terminal instead of the whole desktop (eg with Alt+PrintSc).

  7. Rj

    I have been a Cobol programmer for over 30 years and I believe that I’m quite good at it having been a contractor for much of my career as well as an employee and done very with integrating databases from SQL to DLI and just old batch processing as well as CICS.

    You do not just pick up Cobol programming over a weekend!

    Great so you can write a display statement that’s like neanderthal level programming. It takes a lot of years to get good at just TSO the host background on a mainframe!

    now that you have to go to a graveyard with a Ouija board to find a programmer in Cobol it’s about time that we start getting paid $50-$100 an hour!

    I’m getting ready to retire next year and I plan on freelancing and getting as much as I can for my skills that I’ve been mocked over the years by all these C+programmers well how do you do!

    • Hi RJ, much respect for your 30 years of experience! However I feel the examples provided here are more Cro-Magnon level than Neanderthal. This article was written as a “hello world” introduction as a starting place for anyone interested. As COBOL infrastructures continue to age without replacement, there may not be enough 30-year veterans to meet the demand. When against the wall, the only choice may be to hire those with ANY or even NO experience at all. Concerning your situation? I think you have a unique opportunity to set a fair price for your rare services for a very expensive problem!

    • Ricardo Bánffy

      It’d take a couple articles to cover the IBM mainframe environment where a lot of COBOL code runs, and that would be much better addressed by a magazine that caters to that specific audience. Besides, it’d be pointless to think about CICS, or TSO, or JCL when we are talking about COBOL running on a Linux environment as most Linux users wouldn’t be able to use it.

      I’m not sure Hercules can legally even run TSO, as it was a licensed option when MVS 3.8j (the last MVS it can legally run) was available. For reasons that are understandable, IBM is not a huge fan of Hercules.

    • I am 46 and I was a COBOL programmer for four years. I was quite good in CICS tp monitor too. Right after my high school diploma, I took a one-week course and the week after I was in Florence working for a big italian bank. Of course, I could only get a grasp of it, but you have to start somewhere. I appreciated this article, it made me think about the old days, and I will try to catch up! Can you get paied $100 for hour? Well, good for you, genius! But do not lecture anyone here, try to be supportive!

  8. Darvond

    Or we could let COBOL go the way of the dinosaur, and much like the aging execs who insist on keeping it and the systems requiring it around, replace them with newer systems open to new ideas. The onus shouldn’t be on people to maintain 60+ year old code that is barely documented, has over 300 individual dialects, and runs on machines that should be sitting in a well kept computer museum somewhere.

    This article (to personal opinion) would be better if presented as either virualizing the COBOL code to put it in a specimen tube before having it converted into something for a more civilized age, like C or Rust or a discussion of how to convince others to leave COBOL behind after showing how much more functional and easy it would be to simply reprogram in another language.

    Just looking at those two examples already exemplifies how hairy & unmaintainable the code is.

    Besides, why exemplify something that doesn’t exist? It was made before 1970, and everyone knows it’s only a myth that things existed before then.

  9. Katsuharu Tanaka

    COBOL is an old program language, but it still runs on mainframes of financial institutions. Being able to simulate the program on Linux is also useful for education.

  10. marmez

    Please, correct a typo. “Fibonocci” → “Fibonacci”.

    • I checked and re-checked that spelling 10 times over and I STILL messed it up! My apologies.

  11. marmez

    Should the program also run ENDFIB and print out ending text [1]? I don’t know COBOL, but the code [2] seems to be skipped [3]. If so, is the COBOL so strict to presence of a section even if it’s code won’t run?

    Thanks for the article!




    • Barry

      Move the STOP RUN. to after the GOBACK. in the PROCEDURE DIVISION. and you will see the final ENDFIB. message appear.

    • Danny

      Yes, ENDFIB does indeed run and display the end program message. Just enter an invalid number (one greater than 92) and you will see it.

  12. Simon Sobisch

    I highly suggest to replace the initial -v (verbose compile) by -V or –version.
    Possibly also use a different USAGE as BINARY-C-LONG is a GnuCOBOL only extension.
    Other than that: nice article!

  13. Christian Groove

    Dear fellows,

    ole ole memories are coming up. It must be 2005 when i was involved in a Host/IMS Project and my jobs was to design and implement a piece of code, that should allow a bank-application to access a UNIX based services.

    Incredibly, an old host application running in a IMS transaction should access a UNIX service. I still had some knowledge in COBOL and was an expert in server programming using UNIX socket. The question was, is a IBM Host able to call the socket api?

    So i developed a COBOL application on Linux, that performed some asynchronous socket operation. Since the previous gnu-COBOL project was a neverending story i tried cob2c from Keisuke Nishida. It was a success at all, i was able to code proper COBOL code. The colleague compiled it on his host and finally we were able to access the UNIX-services on a Solaris ES.

    Yes it was 2004 or 2005 when we made it, thanks to Keisuke great work. Some years later, some gnu must have recognized, that the cob-c compiler was a better solution than the old gnu-cobol.

    Thank you Keisuke!

    I was using this compiler, when Keisuke Nishida released first versions of his great COBOL2C Compiler

  14. Christian Groove

    sorry a correction:

    Dear fellows,

    ole ole memories are coming up. It must be 2005 when i was involved in a Host/IMS Project and my job was to design and implement a piece of code, that should allow a bank-application to access a UNIX based services.

    Incredibly, an old host application running in a IMS transaction should access a UNIX service. I still had some knowledge in COBOL and was an expert in server programming using UNIX sockets and TLI. The question was, is an IBM Host able to call the socket api? (Yes it was! 😉

    So i started to develop a COBOL application on Linux, that used some asynchronous socket operations. Since the previous gnu-COBOL project was a never ending story i tried cob2c from Keisuke Nishida. It was a success at all, i was able to code proper COBOL code. The colleague compiled it on his host and finally we were able to access the UNIX-services on a Solaris ES.

    Yes it was 2004 or 2005 when we made it, thanks to Keisuke great work. Some years later, some gnu must have recognized, that the cob-c compiler was a better solution than the old gnu-cobol.

    Thank you Keisuke!

  15. gmgod

    Damned, that was “down-there” in the list of topics I was expected to find published here (or anywhere to be honest)!

    Still a pleasant surprise, if only a purely academic one. 😉

  16. Lawrence Riddick

    I started with RPG and went COBOL many decades ago and appreciate this article.

  17. Frederik

    I take this article as a clear sign from otherworldly powers to study Cobol. I was planning to do that already, so I can’t really argue against it.

  18. tsyang

    After I graduated from college in 1983, the first job required me to write a data management program on a CDC Cyber 170 in any standardized programming language. I picked COBOL due to two needed features: (1) indexed sequential access file, and (2) arbitrary precision numbers. I finished the assignment way ahead of the deadline. Prior to that, I wrote FORTRAN, Pascal, and Basic in college. None of these languages had the two features built-in. Thanks COBOL.

    • Ricardo Bánffy

      I absolutely love the Cyber consoles. My dream job would offer me a setup with dual round screens, but the single square vector one would suffice.

  19. Vincent Coen

    For full set of manuals for GnuCOBOL go to :

    scroll down until you see ‘Work in-progress ‘

    and select your paper format of choice i.e., A4 or letter (USA)

    for the three different manuals namely :
    Programmer Guide
    Quick Reference
    Sample Programs

    also a bit further down another useful manual is :

    GnuCOBOL grammar PDF

    These all relate to v3.1.2 of the Cobol compiler and the first three are maintained as an when errors or additions are reported or needed.

  20. MC

    Hey Donnie, that’s great!
    Full time COBOL developer for about ten years (long time ago) but now I’m on sysadmin for cloud platforms (Openshift, Kafka, ELK stack) and doing only bash and ansible scripts 🙂
    Installed it on my personal laptop to have some fun (and nostalgia).

    Thank you!!

  21. Nehad Shello

    Could we make a web application program with COBOL?
    If yes; Which framework is recommended?

  22. In order to properly do it, you’ll need an IBM terminal font. I strongly, and self-servingly, suggest I have no idea how to build an RPM package or how to get it included in the Fedora repos, so any help with that would be deeply appreciated.

  23. Leslie Satenstein, Montreal,Que,Canada

    55 years ago, I was a cobol programmer. My work as programmer was on an IBM 360 computer complex. The mainframe computer knew about packed decimal, binary, and floating point. The mainframe did not have string operations.
    A good programmer aligned the fields in structures and records so as to begin and end on word boundaries.

    Those were the days where we were lucky to get to compiles per day, and where computer security was non-existent.

  24. Den

    Interesting stuff! Now I’m torn between learning about COBOL or about 6502 assembly…

    • Ricardo Bánffy

      COBOL has more commercial value. With 6502 you can have a lot of fun with Apple IIs, Ataris, C64’s and BBC micros…

      • Den

        Well, I have no inclination to try muscling in on the COBOL experts out there but I do have three of the four systems you’ve mentioned and have been wondering what’s going on inside their cases…

  25. Dave Hugh

    COBOL was my first programming language. Seeing it again brings back fond memories, it makes me want to write a date management routine for an insurance company!

  26. Jack

    What build system is normally used for COBOL ?

    Make, CMake, Ant ?

  27. Nehad Shello

    Is there a library/framework for the web development in COBOL?

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions