Pages

Search my Blog!

Monday, May 31, 2010

How to Compile C program from Ubuntu Terminal

It is really very easy to do that. Just follow these steps:
1) Open the terminal: Go to Applications => Accessories => Terminal
2) Create folder in home directory (It is always a good practice to save your programs in one folder. You may create it anywhere for your convenience)
Type the following in your terminal to create folder then press enter key

mkdir cprograms

Notes:
  • cprogram is the name of your folder, replace it with the name you like!
  • Skip to step three if you have your folder ready

3) Change directory to this folder you have created. Type the following and then press enter

cd cprograms

4) Create the source file. This is the file containing your source code. Suppose our file is named hello.c

gedit hello.c

5) In the editor that opened, type your program. Suppose the program is to display Hello World! on the screen, you type the following

#include
int main(){
   printf("Hello World!\n");
   return 0;
}

6) Save and close your editor
7) Compile your program: Type the following then press enter

gcc -o hello hello.c

Notes
  • gcc is GNU C Compiler, it is shifted with ubuntu, and get installed automatically once you install ubuntu in your box
  • hello is the executable created after successfully compilation
8) Run your program. Type the following and then press enter

./hello

9) you will see your program output displayed on your terminal. In our example "Hello World!"

That is all you can do to create and run your program.

Saturday, May 22, 2010

Installing Sun’s JAVA on Ubuntu Lucid Lynx (10.04)

I successful installed Sun's JAVA on Ubuntu 9.04 (Jaunty Jackalope) and later, on Ubuntu 9.10 (Karmic Koala) I upgraded from 9.04. With introduction of Ubuntu 10.04 (Lucid Lynx), I decided not to upgrade but freshly installed it.
When I tried to install Sun (Oracle) Java, through apt-get, I got the error message saying package (sun-java6-jdk) is missing. After researching on net, I found that since Lucid Lynx, Ubuntu opted for OpenJDK, which I think is a good I idea. But what about those previous programs that explicitly need Sun Java? What about those who are using Sun Java to learn Java programming as part of their curriculum? Good news, Ubuntu still shipping Sun Java, but in partners section. So you need to add that section to your sources and install Sun's JDK as follows:

#sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
#sudo apt-get update
#sudo apt-get install sun-java6-jdk

You will need to accept the license agreement.

You may also need to install the java plugin for firefox. This is done as follows:

#sudo apt-get install sun-java6-plugin

After installing, your Ubuntu has two jdk, OpenJDK and Sun's JDK. If you want to use Sun's JDK instead of OpenJDK (which is the default option) type the following command:

#sudo update-alternatives --config java


A window will open showing your installed jdks, from there, you can change to your preferred jdk.

Next, I will write to you the difference between OpenJDK and Sun JDK.

Any comment? Any question? Welcome again.

Les's Share our knowledge, let's share our experience

Dear all.
This is is my first post at my blog. And it is better I introduce my self. I am writing from Iringa, Tanzania. A small town in southern highland zone of Tanzania. A town whose population is full of university students.

I am writing this to share some technical knowledge about Ubuntu especially to beginners. Beginners who are migrating from windows or any other operating system, who need to be problem solvers.

I want these blog to help my beloved students, who are searching here and there on the web looking for solutions on how to use Ubuntu in their daily student life. On how to write the small programs using various languages including Java, Pascal and C. And generally how to make sure everything they were doing with windows can equally and and more efficiently done with Ubuntu Linux.

The following is the Ubuntu Promise and philosophy(I love it)

The Ubuntu promise

  • Ubuntu will always be free of charge, along with its regular enterprise releases and security updates
  • Ubuntu comes with full commercial support from Canonical and hundreds of companies from across the world
  • Ubuntu provides the best translations and accessibility features that the free software community has to offer
  • Ubuntu core applications are all free and open source. We want you to use free and open source software, improve it and pass it on.
Our work is driven by a philosophy on software freedom that aims to spread and bring the benefits of software to all parts of the world. At the core of the Ubuntu Philosophy are these core philosophical ideals:
  1. Every computer user should have the freedom to download, run, copy, distribute, study, share, change and improve their software for any purpose, without paying licensing fees.
  2. Every computer user should be able to use their software in the language of their choice.
  3. Every computer user should be given every opportunity to use software, even if they work under a disability.

So that is the Ubuntu Philosophy and their promise. I believe you also love it.

Therefore, let's Love Ubuntu, let's Use Ubuntu, and let's Share Ubuntu, by sharing our knowledge and experience.