C Installation and Environment setup

In this tutorial, you will learn how to install and set up an environment for C programming in various operating systems by yourself.

Try It Option Online

Nowadays, compiling C online has been a trend among programmers for short projects.  It comes with many benefits which are as follows:

  1. Newer versions of C compilers used to be published regularly, so the latest offline compiler of today becomes obsolete tomorrow. Here online compilers come in handy and you have to never worry about the version of the software.
  2. Downloading and installing software requires a fair amount of space and speed and it becomes a factor, especially in the case of machines with lower configurations. Online compilers help you get rid of these problems.

C programming

Writing a C program is accomplished in two simple steps coding and compiling. You can do the coding in different text editors like notepad on Windows OS, TextEdit on Mac OS, and gedit on Linux OS. Then the compiler OS runs which reads the codes line by line and searches for errors. If any errors or abnormalities are found they are flagged as 'error' and 'warning'. After the debugging is done and the compiler finds the code to be error-free, it produces an executable file with an extension of '.exe'. the following diagram shows the overall process of C programming.

In most Mac and Linux environments, free C compilers are available that work in command prompt or terminal windows. To run these compilers generally some specified commands or arguments containing 'cc' or 'gcc' are used. In the case of Windows, you may opt for a graphical user interface using IDE(Integrated Development Environment). Most popular IDEs are Microsoft Visual C and C++, Eclipse (Java-based), etc.

Local Environment Setup

To create and execute programs locally you need two important things in your system. They are:

  • Text Editor
  • Compiler

Text Editor: Text editors are used to writing programming codes as simple texts. Text editors l fed the compiler with codes only that can be easily understood and executed by the compiler. Another great feature of a text editor is syntax highlighting. In the text editors, different groups of keywords of C come in different colors, even if it reminds you if you have missed the opening or closing braces during coding. Most text editors are versatile in nature, and they determine the programming language by detecting its extension name. Quick navigation is another great feature of theirs which allows you to jump to a specific line of a program by just entering a command and line no.

The C compiler: There are different types of C compilers in the market, but Turbo C++ is best for beginners. It is a successor of the Turbo C compiler from Borland which was first introduced in 1987. It can run in MS-DOS and Windows as well and the first C++ version was released in 1990 which gained immense popularity worldwide.

Why IDE?

An Integrated Development Environment allows you to build, compile and run your program from a single platform. The latest and most popular cross-platform IDE  is Code::Block. it supports Mac, Windows, and Linux operating systems. Here you can see how to download and install Code::Block in Windows 10, Linux, and Mac.

How to download IDE -CodeBlock to your system

Code::block is the most recent and popular used IDE in Windows OS. The steps to install this IDE are as follows:

  1. Download the IDE by visiting their official website through www.codeblocks.org
    building blocks of object oriented programming
  2. You have reached the official home page of codeblocks.org where you can find the download tab which you need to click. On clicking the download tab you will be taken to the download page where many options are awaiting you. Just click on the Download the binary release that comes first on the page.
    building blocks of object oriented programming
  3. Click on the Download the binary release will move you to another page where you can find the multiple options for downloading the proper version for your OS.
    building blocks of object oriented programming
    1. Windows Version
      building blocks of object oriented programming
    2. Linux Version
      building blocks of object oriented programming
    3. Mac Version
      building blocks of object oriented programming
  4. On clicking sourceforge.net downloading automatically happens and you can see a  window as shown below while downloading.
    building blocks of object oriented programming
  5. When the download is completed you will get the notification in download as shown below. You can right-click on the arrow and show in the folder which will take you to the download folder in your system
    building blocks of object oriented programming

How to install C on Windows :

Now double click on the setup to run it and follow the following steps.

  1. Click the next button to continue
  2. Accept the license agreement by clicking the 'I agree' button underneath.
  3. The below window asks you to choose the components you want to install. just click the next button as there is no necessity to uncheck the components.
    Ensure that "MinGW Compiler Suite" is checked as this option will install GCC on your system.
  4. Next, select the destination folder. By default, it will provide a location on your system. If you want to change the location you can do that by browsing the desired location and clicking on the install button.
  5. The installer proceeds to install the finish the installation of the code block.
  6. Click on the yes button if you want to run the code::block now. otherwise, you can click on the No button.
  7. Finally, click on the finish button to complete the installation

Initial Run on Windows

  1. To launch code blocks there are two ways -
    • Go to Start ---> All Programs ---> Code Blocks
    • Double click on the shortcut icon of code blocks on your desktop
  2. Now Code Block will ask you to select the default Compiler. In case your system has some other compiler besides GCC, Code Blocks will detect all of the compilers available on your system and will show you a list in the window. In our case, as we do not have any compiler other than  GCC, only GCC is detected here. Click on "Set as default" to set the GCC as the default compiler  as shown in the screenshot below:
  3. For the first time running Code Blocks, you may get a window as given below asking you to select Code Blocks as a default application for  C/C++ source files. Select the first option and click OK.
  4. Eventually, you will reach the start page of the code block.

How to install C on Linux/Ubuntu:

For Linux Mint or Ubuntu-based systems, the GCC C++ compiler works best. It is easier to install code block in Linux since it is already available in the package repository. Since CodeBlocks executes on various Linux versions such as Ubuntu, Fedora, CentOS, etc you can choose the desired one from the download list. 

Follow the below steps to install CodeBlocks in Linux.

  1. Open the terminal and type the following command to add the PPA repository
            
    sudo add-apt-repository ppa:damien-moore/codeblocks-stable
        
        
    when it prompts, type the user password, and hit enter.
  2. Before installing the compiler it is advised to update the system using “sudo apt-get update” which will update all the packages on the system.
        
    sudo apt update
        
        
  3. Lastly, run the below command which will initiate the CodeBlock installation.
        
    sudo apt install codeblocks codeblocks-contrib
        
        

We have successfully installed CodeBlock on Ubuntu.

Installation of C on Mac Os:

Install of the compiler using XCode is most preferred because of its robust support system. Installation of CodeBlock in Mac involves three different steps for setup, which are:

  1. Download Xcode from the App store by signing in and searching  X code and get it 
  2. Now download the CodeBlock setup for the mac which is a zip file. 
    1. Once downloading gets completed, extract all the files and you will get the CodeBlock application file.
    2. To install drag and drop the file to the application folder.
  3. Finally, install the command-line tool which allows you to call the compilers from the command line.
    1. Go to the Apple Developer download page
    2. Click the Command Line tool for Xcode 
    3. Download the dmg file
    4.  Double click on the package file to download the command-line tool and accept every default.

Thus we have installed CodeBlock on mac successfully.
Last but not least your compiler is ready to compile programs. In the following tutorial, you will learn to create your new and first C program.