how do i compile code and write code in ubuntu?

do i just do it in notepad and do it with the terminal and what are the terminal commands to compile it or is their a compiler i can use...i want to try coding on a linux
Yes you can do it in notepad (or equivalents) or there are fancier IDEs available (Eclipse)

You will need gcc / g++ for c / c++

If you use the synaptic package manager it will make sure you get all the relevant dependencies
Last edited on
g++ should be installed. If it's not, then you can get it using this command in the terminal (if you're an admin): sudo apt-get install g++. It will ask you for your password, which you will have to give (otherwise you'll run into some problems with the installation.

Once you have it, two possible syntaxes for using it from the console are:
g++ input_file(s)
g++ -o output_file input_file(s)


To create the input file(s), your standard-issue Text Editor (gedit) will do, although you can download Code::Blocks/Netbeans/Eclipse which are more full-featured IDEs, like Jimbot said.

Have fun!

-Albatross
Last edited on
An IDE : Geany can help you,it just work as Ides on windows .
For Ubuntu, Eclipse or Code::Blocks would probably be best. GCC should come with the build-essential package, which you probably already have. Your questions imply that you don't really understand what a compiler actually is though.
you should also try in-line (you can access them from terminal) editors such as emacs or vi, if you don't already have them you can google them to install them easily. This allows you to just type "emacs new_file.cc", type your code, then save it and go back to terminal, then type "g++ new_fie.cc -o new_program". (or gcc in place of g++). the -o new_program part is saying the name of the output file, if you just say g++ filename it automatically saves it as a.out, assuming there are no errors. then you just type "./a.out" or "./whatever_filename_you_specified" and it will run, all without leaving your terminal!

For java quickly, you would do "emacs something.java" or "vi something.java", then to compile say "javac something.java", then to run just say "java something", with no extension
Last edited on
try using "vim filename.c or .cpp"
u can use gedit if not install type
sudo apt-get install gedit
I strongly urge you to go with Emacs. I use to be a die-hard Vi user, but one day I figured why not give Emacs ago, and get a fair view of things. At first I disliked it to be frank. I missed my Vi commands, and I found relearning simple commands frustrating. After about two weeks, I felt very confident with it, and now it's customized to a point where I prefer it over Visual Studio. It's got better tab browsing, searching, syntax highlighting, paren highlighting and auto-completion and obviously improved editing commands. Once you learn it it's fantastic, and I can give you my .emacs and some useful plugins if you want :)
Simple coding for Ubuntu:

In a terminal run:
1
2
3
4
5
6
1. sudo apt-get install build-essential (gets g++ and others)
2. nano or gedit a .cpp file.
3. Save the file.
4. Using the terminal navigate to the folder.
5. g++ -o filename filename.cpp
6. ./filename //runs the program. 
Install Anjuta from Ubuntu Software Center and start coding, this is the simplest way.
I still say go with Emacs and make :)
Last edited on
Topic archived. No new replies allowed.