Installing Compilers (GCC,G++ and Java) on UBUNTU

This tutorial is not written from scratch. I would like to thank all people who
enlightened me about Linux and Open source. This tutorial acknowledges the
help of Ubuntu Community (Docs) and people at online forums who cleared
my doubts on compilers.
Installing compilers is one of the easiest things there out at Linux. It
may seem a bit tough and complicated in the beginning but apt-get
and Synaptic Package Manager simplify your work a lot. As a newbie
developer you would require a C/C++ and a Java compiler. Installing
them is a matter of few commands.
The GNU C and GNU C++ Compiler:
The GNU C compiler is also called gcc and C++ is called g++. You
may also require the GNU make utility. All of them can get installed
by getting the build-essential package.
Just use this command:
sudo apt-get install build-essential
The GNU Java Compiler:
Firstly note that this compiler is not the one provided by Sun. The GNU
Java compiler is named as gcj. Just install the package gcj
To install the GNU Java bytecode interpreter, install the gij package.
To have gcj compile to executables, install libgcj6-dev
Use the command:
sudo apt-get install gcj gij libgcj6-dev

UPDATE ON 10th July,2006:

Some people complain that the above method does not work on their system. Errors like “build-essential not found” are displayed. Here is an alternate way of doing the same:
Most people want to use linux in GUI mode just like windows. If this the case then why use the terminal? Just open the Synaptic Package Manager and search for the package gcc. Select the package, some more packages will be highlighted and will be asked to also be included in the install process. These are dependencies. Select them also and click on Apply. The packages are download and installed. To install g++,make and gcj just do the same as above mentioned for gcc package.
Well its done, now try compiling, it should work.

Advertisements

52 thoughts on “Installing Compilers (GCC,G++ and Java) on UBUNTU

  1. i typed the command sudo apt-get install built-essential and the system responded with an error ” couldnt find package built-essential” plz help

  2. I suggest you to install it via synaptics package manager, in synaptics just search the package gcc, all the dependecies will be shown and you will be asked to download these also….
    After doing the above steps, try downloading g++ which is the C++ compiler for linux,its always better to install packages via Synaptics if you are not very confident as it gives you all the dependencies also….
    Hope you have an active internet connection,its required…

  3. This is all i need.Thank you very much Sir.
    Can you tell me more about the packages,i mean i want to download the packages with a .deb extension & want to install it latter manually from the terminal.How can I do so?
    Please help…

  4. I dont suggest you to get a .deb package and install manually.
    Manual installation is a pain as most of the packages have dependencies which are difficult to track down manually. Use the package manager and it does everything for you

  5. i am not able to install even 1 package yet.all the package installations give an error saying unable to connect to the website while i have a net connection what shud i do?

  6. Chandra,
    Are you behind a proxy? This problem comes when you are behind a proxy, even though internet may be fine, Apt must know about the proxy server.

  7. Put in the Ubuntu CD in the tray, Goto System>Administration>Software Sources and select CD. Click on Close, it would ask you to reload the index. Click “Reload”

    Now goto synaptic package manager and select “build-essential” package and its done.

  8. I went to Synopsis Pckg Mngr and did the same you said above to install gcc compiler but still when I go to terminal andtype gcc it says “no input files”
    What is wrong?

    Thanks

    1. You need to use gcc with filenames are input, gcc isnt a GUI compiler.
      Use it like this

      gcc inputfile.c -o outputfile

      then execute it:

      ./outputfile

      Example:

      gcc server.c – o server
      ./server

  9. Hi
    I am new to ubuntu and done install with windows through net. Now my net is working fine with XP but not with ubuntu. It seems there is a driver problem as it is showing mac addr field all 0’s. I am using RT8169.
    I also want to install gcc compiler, procedure through internet I know but problem is I can connect on window but not on ubuntu as mentioned earlier.
    Pl suggest what should be my next action

  10. Hi
    This is in continuation to my previous mail, I just happened to find installation CD for my LAN card(RT 8169).
    now pl tell how to install LAN card using this CD
    thanks
    skumar

    1. First you need to tell me whether this installation CD had windows drivers or Linux ones. Or does it contain the source code. Tell me the contents of the CD, then I can help you.

  11. Hi
    Thanks,I am able to configure the DSL modem on my USB and can use internet. I also install g++ compiler with the help of build essential.
    As far as LAN card is there it is having folder Linux-kernel 2.4x 2.6x. In this folder following things are there
    -Src
    -Makefile
    -Readme
    -Releasenote

  12. Hi
    I don’t have a ubuntu Cd or net connection, how do i install g++? Do any chance of downloading it into cd and install it?

    1. You problem is very unusual. Get hold of the Ubuntu CD. That is the most easiest solution.
      More complicated ways are to download on another pc with net connection and then copy it and install it here. Details here:
      http://is.gd/5X1ap

      Anyway g++ is already installed, all you need is the development headers

  13. Sir,
    I tried the command :
    sudo apt-get install build-essential
    it executed.
    But when I tried to compile a very simple code to print HELLO WORLD it is showing the following error messages :
    hello.cpp:1:21: error: iostream.h: No such file or directory
    hello.cpp:2:18: error: conio.h: No such file or directory
    hello.cpp:5: error: ‘::main’ must return ‘int’
    hello.cpp: In function ‘int main()’:
    hello.cpp:7: error: ‘clrscr’ was not declared in this scope
    hello.cpp:8: error: ‘cout’ was not declared in this scope
    hello.cpp:9: error: ‘getch’ was not declared in this scope

    please help me as I am new to this environment.

    1. The medium with which you install has nothing to do with what packages are present. If you install by CD, then same thing would be present in USB install too. The contents are the same, just the installation medium changes.

  14. i found folder ‘pool’ in my usb ubuntu installer, there’s subdir main n restricted. Then i saw dir g++ inside them. Can u tell me how i install g++ via usb as cdrom instead?

  15. just a moment ago, ive success installed g++ n run it with geany. I didnt realize thre is simple way. Just find n instal deb file in ur cd or usb stick which located in pool/main/g/… There are 3 file deb… Sorry 4 bothering u man…thx again.

    1. That looks simple, but not recommended. I would always say everyone use package manager and avoid messing around with .deb files themselves.
      The package manager is there for a reason

      1. Hi
        I want to install g++ compiler into Ubuntu, but im not able to do.
        I gave the command sudo apt-get install g++
        i got an error coudn’t find the package g. Now how to install

  16. it happened on trying to install using the command specified. please help,,
    how to provide proxy authentication??
    ____________________________________________________________
    upvan111@ubuntu:~$ sudo apt-get install build-essential
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    The following extra packages will be installed:
    dpkg-dev g++ g++-4.4 libalgorithm-diff-perl libalgorithm-merge-perl
    libdpkg-perl libstdc++6-4.4-dev
    Suggested packages:
    debian-keyring g++-multilib g++-4.4-multilib gcc-4.4-doc libstdc++6-4.4-dbg
    libstdc++6-4.4-doc
    The following NEW packages will be installed:
    build-essential dpkg-dev g++ g++-4.4 libalgorithm-diff-perl
    libalgorithm-merge-perl libdpkg-perl libstdc++6-4.4-dev
    0 upgraded, 8 newly installed, 0 to remove and 324 not upgraded.
    Need to get 8,078kB of archives.
    After this operation, 24.3MB of additional disk space will be used.
    Do you want to continue [Y/n]? y
    Err http://us.archive.ubuntu.com/ubuntu/ maverick/main libstdc++6-4.4-dev i386 4.4.4-14ubuntu5
    407 Proxy Authentication Required
    Err http://us.archive.ubuntu.com/ubuntu/ maverick/main g++-4.4 i386 4.4.4-14ubuntu5
    407 Proxy Authentication Required
    Err http://us.archive.ubuntu.com/ubuntu/ maverick/main g++ i386 4:4.4.4-1ubuntu2
    407 Proxy Authentication Required
    Err http://us.archive.ubuntu.com/ubuntu/ maverick-updates/main libdpkg-perl all 1.15.8.4ubuntu3.1
    407 Proxy Authentication Required
    Err http://security.ubuntu.com/ubuntu/ maverick-security/main libdpkg-perl all 1.15.8.4ubuntu3.1
    407 Proxy Authentication Required
    Err http://us.archive.ubuntu.com/ubuntu/ maverick/main build-essential i386 11.5
    407 Proxy Authentication Required
    Err http://security.ubuntu.com/ubuntu/ maverick-security/main dpkg-dev all 1.15.8.4ubuntu3.1
    407 Proxy Authentication Required
    Err http://us.archive.ubuntu.com/ubuntu/ maverick/main libalgorithm-diff-perl all 1.19.02-1
    407 Proxy Authentication Required
    Err http://us.archive.ubuntu.com/ubuntu/ maverick/main libalgorithm-merge-perl all 0.08-1
    407 Proxy Authentication Required
    Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/g/gcc-4.4/libstdc++6-4.4-dev_4.4.4-14ubuntu5_i386.deb 407 Proxy Authentication Required
    Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/g/gcc-4.4/g++-4.4_4.4.4-14ubuntu5_i386.deb 407 Proxy Authentication Required
    Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/g/gcc-defaults/g++_4.4.4-1ubuntu2_i386.deb 407 Proxy Authentication Required
    Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/d/dpkg/libdpkg-perl_1.15.8.4ubuntu3.1_all.deb 407 Proxy Authentication Required
    Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/d/dpkg/dpkg-dev_1.15.8.4ubuntu3.1_all.deb 407 Proxy Authentication Required
    Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/b/build-essential/build-essential_11.5_i386.deb 407 Proxy Authentication Required
    Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/liba/libalgorithm-diff-perl/libalgorithm-diff-perl_1.19.02-1_all.deb 407 Proxy Authentication Required
    Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/liba/libalgorithm-merge-perl/libalgorithm-merge-perl_0.08-1_all.deb 407 Proxy Authentication Required
    E: Unable to fetch some archives, maybe run apt-get update or try with –fix-missing?
    ______________________________________________________________
    please respond soon… thank you

    1. Thank you so much for your help. I have done all the steps except:7. From wiithn the gcc-build folder run,../gcc_4_3_4_release/configure enable-languages=c,fortran target=x86_64-apple-darwin -build=x86_64-apple-darwin host=x86_64-apple-darwinTo do this, am I in terminal?? I dont understand. The gcc-build folder is empty. How do i run this from there?8. Compile gcc, gfortran, and the associated libraries (this will take a while),make -j4Do I type make-j4 in terminal to compile gcc,gfortran and associated libraries?? how exactly do i do this?9. Finally you can install this with,sudo make installDo i just type sude make install in terminal??

  17. I am going to install NetBeans to start developing my own programs. I have heard that besides gcc, g++, and make you also need gdb (GNU debugger). Is gdb necessary, or is it optional? Is gdb included in the build-essential package? If not, then how to install it?

  18. $ sudo apt get install build-essential
    $ sudo apt get install gcc
    when i execute this command for g++…
    Reading package lists… Error!
    E: Encountered a section with no Package: header
    E: Problem with MergeList /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_natty_main_binary-i386_Packages
    E: The package lists or status file could not be parsed or opened.

    1. I have done all the steps with no error messages. I aemsusd that gfortran 4.3 is included in gcc4.3.4 but this is the only thing about which I am not sure. If I should installl gfortran4.3 I was not able to find that version (but only last version 4.6.x) in the link provided by you. Thanks a lot for your helpThen, after doing all steps and with my assumption taken on board I got the following error:mex timestwo.F/Applications/MATLAB_R2010b.app/bin/mex: line 1041: gfortran: command not found mex: compile of timestwo.F failed.??? Error using ==> mex at 208Unable to complete successfully.

  19. can you help me to start my database project?
    outline:
    The second part will be the application. The choice of front end is up to you. The requirements for the
    application are as follows:
    1. You need to authenticate to use the system.
    2. There should be two levels of authentication. One set of users should be able to manipulate the
    time table, while another set should just be able to only view the time table.
    3. You should be able to input a schedule in the system.
    4. You should be able to view, update and delete time table entries from a tabular format/view.
    5. You should be able to run filters on the time table view.
    eg. I should be able to just view all Lectures or all Labs or all Tutorials.
    5. You should be able to click on a button to get this report: The Names of lecturers and the activity
    that they are teaching for the current semester.
    NB: Useful additional features will be awarded with extra marks.

  20. type this command in terminal:- $sudo apt-get install root-system-bin
    after this command it will ask the sudo password type your ubuntu login password it will insert the root with g++

  21. i am very new to this. i have been using turbo c in windows but i dont know how it works in linux.
    i have installed g++ but i wanted to know where to write the code and some sites say that u have to save in the same directory. what does that mean?

  22. Hi
    I want to install g++ compiler into Ubuntu, but im not able to do.
    I gave the command sudo apt-get install g++
    i got an error coudn’t find the package g. Now how to install

  23. i want to install gcc and g++ compiler i tried alot using build-essential and through synaptic manager but i got authentication error every time:(

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