How to Install Curses.h library On Linux

Subscribe

Before we begin to install curses.h Library, consider the necessity of curses.h in Linux.

If you’ve done any basic Unix programming, you’ve probably come into the need for text user interface functions like moving the pointer on the screen, editing input given by users, using different colors, and so on. Such terminal IO operations are not portable and are not described in the C programming language. You must use the curses library or the low-level termcap library. It is significantly simpler, more portable, and easy to use the curses/ncurses library.

In this article, we will be focusing on how to install curses.h/ncurses Library on Ubuntu 20.04. Ncurses, commonly known as the new curses library, is basically/also known as a curses emulator that can be run on System V Release 4.0 (SVr4) as well as on other systems. Ncurses is a free, easily understandable, and open-source library. It uses the terminfo format (It means that every line ends with the comma (,), supports pads and color and multiple highlights, forms characters, and function-key mapping, and has all of the additional advantages that SVr4-curses have over BSD curses.

Note to Remember:

curses.h is the part of ncurses library in Linux. So, to install curses.h it is necessary to install ncurses Library.

So, I hope that the usage of curses is understood. Let us now look at how to install curses.h library.

Installing Curses.h Library On Linux

Step 1: Upgrade The Server

To install any software or package on your system, it’s necessary to update your System as this will help you to keep your system up-to-date and let your system know if any changes are made in the packages like their update or anything (like the addition of new features). So, before installing the package, just remember to update your system.

sudo apt update && sudo apt upgrade
Upgrade The Server
Upgrade The Server

Note to Remember:-

You must have Administrative rights to your Ubuntu 20.04 LTS, hence you must be the root user.

Step 2: Download and install the ncurses library

To install curses.h/ncurses library, use 

sudo apt-get install libncurses5-dev libncursesw5-dev
Download And Install Curses.h Library
Download And Install Curses.h Library

This command will help you download and install all the required packages, as well as all of their dependencies, files, and necessary Directories, from the default Ubuntu repository.

Step 3: Determine the Installation of Package

You may ensure that the relevant library package was installed by running the commands, as shown below.

dpkg -L libncurses-dev libncurses5-dev libncursesw5-dev 
Determine The Installation Of Package
Determine The Installation Of The Package

Step 4: Removing the Ncurses Library Package

Simply run the following command to uninstall or remove the above-mentioned installed package. This will delete the installed package from your system.

sudo apt-get remove libncurses5-dev libncursesw5-dev
Remove The Ncurses Library Package
Remove The Ncurses Library Package

Note to Remember:-

Remember to carefully use the following command, as it may delete any of the dependent packages utilized by other applications or processes those are currently running or being executed on your System.

Even if you continue to receive the Linux problem,

“Curses.h: no such file or directory exist”

Linux Error
Linux Error

Try to install curses.h/ncurses library again (repeat step 1) However, if you see the problem when using Alpine Linux (a Linux distribution), 

apk install ncurses-dev

If you’re running Fedora, RHEL, Alma Linux, CentOS, or Rocky,

yum install ncurses-devel ncurses

Now you can write any code in your familiar editor like Vim or Nano of C Language to run it.

Frequently Asked Questions (FAQs)

  • Explain the use of the ncurses Library in C.

The first line of code in main is initscr(), which launches ncurses. The next line just prints a heading, but notice how it uses addstr, one of a few ncurses functions for printing. Because ncurses output to a buffer, we must call refresh to flush the buffer to the screen.

  •  What is the difference between ncurses and curses.h?

Curses is the name of the initial SystemV library. Ncurses is an open-source library implementation with the same API. Every implementation will supply its own header, such as ncurses.h and pcurses.

  • Who and When was the ncurses Library created?

The package was written in 1982 by Pavel Curtis and maintained by various people until 1986 and first named pcurses. It was later polished (for example, ANSI prototypes, reformatted, some bug fixes, but essentially the same package). Zeyd Ben-Halim released ncurses 1.8. 1 in late 1993.

Conclusion

I hope the above procedure helps you to install curses.h/ncurses Library in your System, as you learn how to break curses.h: No such file or directory problem on Linux after installing the right ncurses library. 

This ncurses Library not only provides a wrapper over terminal capabilities, but also a sophisticated foundation for creating a nice-looking UI (User Interface) in text mode. It has functions for creating windows and so on. Its companion libraries panel, menu, and form supplement the core curses library.