sudo apt-get install codeblocks gcc

sudo apt-get install build-essential nano

nano hello.c

#include int main () { printf("Hello, world!

"); return 0; }

gcc hello.c

./a.out

gcc hello.c -o hello

sudo apt-get install emacs

sudo apt-get install kdevelop

sudo apt-get install anjuta

sudo apt-get install openjdk-6-jre

sudo apt-get install eclipse-cdt

sudo apt-get install codelite

GUI (graphical user interface) with enough development features: Kate , Gedit , Geany

, , simple editor for the terminal: Nano

advanced, powerful IDEs: Emacs , Vim

, other GUI, powerful IDEs: Code::Blocks , Codelite , Anjuta , Eclipse , KDevelop , Netbeans etc

, , , , , etc an overview of 20 text editors for Linux is available here

This tutorial targets especially beginners in Linux and particularly Ubuntu, users who have just recently switched from Windows to Ubuntu and are facing this question: "how can I compile and run my C or C++ programs in Ubuntu?". Most of these users study C or C++ at school and are usually used from Windows with an IDE (Integrated Development Environment - a code editor which offers many other functions, including compiling and running the source code) like Dev-C++ or Code::Blocks.To start with, I'd like to point out that Code::Blocks is also available for Ubuntu, and Dev-C++ can be ran through Wine, a program which allows most Windows applications to be run on Linux (see this Wine guide I put up a while ago).If you want to quick start with Code::Blocks, then go ahead, open a terminal and type:The command above installed Code::Blocks and, the GNU C Compiler used to compile C and C++ code. Now you can go toto launch it and get going.However, I'd like to briefly explain how this works, and I'll introduce two methods: the command-line mode, where all you need is a terminal and an editor which works in a shell, and the other method, which takes into account graphical IDEs with advanced features.For this example we will use Nano, a popular and fast text editor which gets the job done quickly. Two other powerful, but a little harder to master when starting in Linux are Vim and Emacs. First make sure you have all the tools installed. Open up a terminal and type:Nano is almost surely already installed.is a meta package, that means a package which only depends on other packages, and when it is installed it will automatically install several tools like, the C compiler, orNow let's create the first C source file, sayNano will fire up, and let's proceed to write our program. I'll use a simple, hello world example here:Now press ^O (that is Ctrl+O) followed by Enter to save your program, and then press ^X (Ctrl+X) to exit Nano and return to the terminal.This program will print the messageto the standard output, the screen. However, first we have to compile it. To do so, type:Now if you typeto list the files in the current working directory, you'll see a file called. That's our program, and to run it type:You can also specify a different filename for the output program instead of a.out, e.g.:Actually for starters I'd like to point out that a simple text editor with basic developing facilities like syntax highlighting and indentation is a better start than a full-fledged IDE. For terminal use, I'd recommend Nano . For GUI, I'd go with Gedit Kate or Geany There are so many text editors and development applications available it wouldn't make no sense to list all of them here. There are powerful ones like Emacs or Vim which take a little time to master, graphical ones like KDevelop or Anjuta. Some prefer text editors with enough capabilities like Kate, or Geany, or the one included by default in GNOME, Gedit. I recommend reading this comprehensive list of no less than 20 text editors overviewed by me a while ago, so try them and see which fits. I really advice against using a full-fledged IDE like KDevelop for example, which really serves other purposes. Emacs was initially developed by Richard Stallman, the founder of GNU, and it is not only an IDE, but also an email client, web browser, file browser, and much, much more. To install it type in a terminal:Which will install Emacs 23.3 in Ubuntu 11.10 Oneiric Ocelot.Learning Emacs or Vim can be hard when starting, but in time it will prove a time-saver. Emacs differs from Vim completely when it comes to keyboard shortcuts and way of moving around and manipulating text, so I'd recommnd learning one and sticking to it. To open a file in Emacs, type ^X-F then write the path to the filename in the bottom bar. To save a file, type ^X-S (Ctrl+X followed by Ctrl+S). To quit Emacs, use ^X-C. In Vim, you would press I for insert text mode and Escape to enter commands. In command mode,will quit Vim, whilewill write to file.However, if you're not happy with a text editor with development capabilities, let me suggest several dedicated IDEs which you can try.A feature-rich IDE targeted towards developing applications in Qt and for the KDE desktop environment.It's written in GTK, so it blends well in GNOME. Anjuta is a powerful IDE for C and C++.An advanced IDE written in Java, and although aimed towards developing Java applications it can be used for developing in C/C++ too. You will have to download it manually from the official website . Once you've downloaded it, install the Java Runtime Environment to be able to run it:Alternately you can download and install the Java Runtime Environment from Oracle at this address This is the Eclipse IDE with C and C++ development plugins.Another powerful C/C++ IDE ( Homepage ).To round it up, here would be my recommendations for a user who is starting development in Linux: