How to compile and run program code in Ubuntu Linux machine?
Basically, I will tell you how to compile and run three types of code in Linux machine.They are C, Java and Python program code? The C and Java program code is compiled and then we run it. Whereas the Python code is directly run as it is an interpreted language. It does not require you to compile the code before running it.
For C program code, in order to compile and run you will need the gcc compiler. Make sure you have installed the gcc compiler if not install it by using the following command,
$ sudo apt-get install gcc -y
Now let say you have a C program code called sample.c. In order to compile, use the following command
$gcc -o sample sample.c
It will generate the object file with the name sample. You can give any name to the generated output object file. In order to run using the following command,
$./sample
For Java program code, make sure you have installed the java if not use the following command to install java,
$sudo apt-get install java -y
It will install you the latest version of java. Let's say you have the java code called sample.java. Now in order to compile the code using the following command,
$javac sample.java
If your code does not have any syntax errors then it will give you the java class file with the name sample.class. In order to run the code using the following command,
$java sample
Finally, for Python program code, make sure you have the python installed if not install it by using the following command,
$sudo apt-get install python -y
OR
$sudo apt-get install pyhton3 -y
Now in order to run the python code called sample.py, use the following command,
$python sample.py
OR
$python3 sample.py
If you do not have any errors it will give you the output or else it will show the errors.
Have a happy coding!!!.