Hello World in C using Linux and GCC

Follow the steps below to create, compile, and run the simplest possible program in Linux using GCC.

1. Start up Linux, open a console window, and navigate to any convenient directory.

2. At the command prompt, enter “su” and supply the superuser password.

3. Enter the command “mkdir HelloWorld” to create a directory named “HelloWorld”, then the command “cd HelloWorld” to enter that directory.

4. Enter the command “nano HelloWorld.c” to create a new text file named “HelloWorld.c” and to open it in the Nano text editor.

5. In the Nano text editor, enter the text shown below, then save the file and exit Nano by pressing Ctrl-X, then Y, then Enter.

#include 
main()
{
    printf("Hello, World!\n");
}

6a. If using a Debian-based Linux distro such as Ubuntu or Mint, enter the command “apt-get install gcc” and follow the prompts to install the Gnu Compiler Collection.

6b. If using a Fedora-based Linux distro such as RedHat or CentOS, enter the command “yum install gcc” and follow the prompts to install the Gnu Compiler Collection.

7. Enter the command “gcc HelloWorld.c -o HelloWorld” to compile the source code to a program file named “HelloWorld”.

8. Enter the command “./HelloWorld” to run the program. The text “Hello, World!” will appear in the console window.

This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s