How To RUN C and C++ programs on Linux?

Are you a student or programmer on Windows? And do you want to change your platform to Linux? Then of course you can. Here are the some steps to setup programming environment on Linux.

1. Ubuntu:

First we will start with most popular linux distribution i.e. Ubuntu.  In order to run programs on  Ubuntu, you need to have “GCC” and “G++”  compiler installed. Since Ubuntu doesn’t have pre-installed GCC or G++ compilers. So you need to install them.  To install G++ or GCC, open terminal and type the below command: (remember: for this you need to be connected to the internet)

$ sudo apt-get install gcc Note: no need to include $ sign. It is user prompt.

then it will ask for root or administrator password. You have to enter root password. Then it will download GCC package from internet and install it in TERMINAL. Until then you have to wait. After installation user prompt will be returned. Here your installation is done.

To write a C program, open the terminal and type:

$ vi pgm1.c

It will open VI editor for you to write the program. And then press “i” button. This will enable us to write the program. After you write the program press “ESCAPE” button to come out from “Insert” mode. And then press “: i.e colon and “WQ” i.e. “SAVE & QUIT”. Now your program is saved and quit. Now you can run your program by typing following command:

$ gcc pgm1.c

It will run successfully.

2. Fedora:

To run C programs on Fedora you need GCC compiler. First Fedora comes with all the pre-installed compilers. You don’t need to install any compiler packages. You can directly start with Terminal.

Still if you don’t have it, then type the following command in Terminal:

$ su (it asks for superuser or root password)

Enter the password.

Then as root type the following command:

#yum install update

Here it updates all the packages. Then type following command:

#yum install gcc or

#rpm -ivh gcc

To install G++ compiler, type:

#yum install g++ or

#rpm -ivh g++

3. Debian:

Since the Ubuntu Operating System is based on Debian. So to install GCC or G++ in Debian you can use the same commands as mentioned for Ubuntu.

4. openSUSE :

openSUSE is most popular Linux flavor used across Servers and Desktops. It also comes with pre-installed GCC and G++ compilers. If not you can type following command in terminal that will install GCC for you.

$ sudo zypper install gcc

It will ask for root password. Enter it and it will install GCC.

5. Mandriva:

Mandriva is the most user friendly OS as Windows XP. It comes with large number of pre-installed applications along with all compilers such as GCC or G++ etc. You don’t need to install them separately. Even though if you want to install them type below command as root  in terminal:

#uprmi.update -a

#urpmi gcc

Advertisements

Comments Off on How To RUN C and C++ programs on Linux?

Filed under PROGRAMMING

Comments are closed.