Latest Posts

Thursday, November 29, 2007

How to Run C# on Linux OS

Here i am going to explane how to run C#(not GUI based ) on linux OS step wise .
1) Installation Process
a) Go to the following web site
http://go-mono.com/sources-stable/
b) dowanload mono-1.2.5.2.tar.bz2
c) go on terminal (command prompt for windows user )
d) login to root user
e) move mono-1.2.5.2.tar.bz2 to /usr/local/src by using following code
mv mono-1.2.5.2.tar.bz /usr/local/src
f) also move to src directory
cd /usr/local/src
g) type the following command to untar ( ie unzip for windows user ) the package
tar -xjf mono-1.2.5.2.tar.bz2
a new directory is created named " mono-1.2.5.2 "
h) move to that directory and type
./configure (dot then back forward slash )
after the configeratin will finish type
make
after make is created type
make install
All these process take 30 to 35 minute so be clam and coll till the process ends .
After make is installed we are now redy to run and execute c# programe .
2) Runing and Executing the C# programe
I follow the same old method of learning a programin language ie by writing the same old our Hello word program .

a) open any text editor in linux (vim , vi etc )
vim hello.cs
here .cs is C# file extension
for writing on vim editor you have to change your mode from comman to insert . for this press " i ";
// Hello World in C Sharp
class Hello {
static void Main() {
System.Console.WriteLine("Hello World");
}
}
To exit from the vim editor with saving the file type ESC and then Type "wq" and press enter.
(ESC changes insert mode to command mode, wq stands for "write and quit " )
b) Here our first programe is written and saved . now we have to compile it and run it.
To compile it simply type on command prompt
mcs hello.cs
if there is no error then hello.exe is creted else it will return error message
To run this programe type on terminal
mono hello.cs
it will print " Hello World " on terminal

For more detail you can also reffer to this website
http://www.csharphelp.com/archives2/archive317.html

9 comments:

  1. Hi Neeraj,
    Thanks for the very nice step by step instruction. Though I got some errors while running the make command on SUSE Linux OS m/c. I just wanted to try whether the installation is OK, so I tried running compiling hello.cs. It created hello.exe file. When I tried running mono hello.cs as mentioned it gave me this error "Cannot open assembly hello.cs." But mono could run on hello.exe instead of hello.cs. So should the command be "mono hello.cs" or "mono hello.exe". Or am I missing something here..

    Sangeetha

    ReplyDelete
  2. How can i run C#(GUI based) on linux OS any sites or step by step tutorials like this. Now i am able to run NON GUI on linux , but while i try to run GUI it says some error in accessing dll's

    ReplyDelete
  3. Hello
    I am developing an aplication written in Ansi-C on Linux plattform, and I want to communicate with an Windows applikation that have interface written in .NET, C#.
    What to do ?

    ReplyDelete
  4. Hi,

    is there any way if let say i had .exe file compiled using Visual C# and other .dll file and want to execute this on cluster machine running LInux?

    Your assistance is highly appreciated

    Dhorl

    ReplyDelete
  5. In the last 3 lines

    "To run this programe type on terminal
    mono hello.cs
    it will print " Hello World " on terminal"

    Should'nt the command for run be
    mono hello.exe ?

    ReplyDelete