How to install C and C++ Compilers in Ubuntu

by Stephen on October 23, 2009

Simply run:

sudo aptitude install build-essential

This will install cc (C) and g++ (C++) compilers and some others.


Examples:

Using the vi editor to open a file called hello.c:

vi hello.c

and type:

#include <stdio.h>

int main()
{
       printf("Hello world!\n");
       return 0;
}

Now compile the program:

gcc hello.c -o hello

A new file called “hello” should be created, run it using:

./hello

output:

Hello world!

Leave a Comment

Previous post:

Next post: