Development with Linux
Development with Linux is the process of writing, compiling, executing and debugging software applications
using the Linux operating system.
Linux provides several development tools, such as text editors, compilers, debuggers, and functions which
make software development efficient.
The typical development process in Linux is:
1. Write the source code.
2. Save the program.
3. Compile the program.
4. Execute the program.
5. Debug and test the program.
Text Editors in Linux
A text editor is used to create and modify source code files. Linux provides many text editors, among
which vi and nano are the most commonly used.
vi Editor
vi (Visual Editor) is a powerful and versatile text editor available on almost all Linux systems.
It is a modal editor, meaning it operates in different modes for editing and executing commands.
It is widely used by programmers and system administrators.
Modes of vi
1. Normal Mode
Default mode. - When you open a file using vi hello.c the editor is in Normal mode.
Used for navigation and editing commands.
2. Insert Mode
Used to type and edit text.
Enter by pressing i or a.
3. Command Mode
Used for saving, quitting, searching, etc.
Accessed by pressing Esc, then typing :.
Basic Commands
Command Purpose
vi filename Open or create a file
i Enter Insert Mode
a Append text after the cursor
Esc Return to Normal Mode
dd Delete the current line
Command Purpose
:w Save the file
:q Quit
:wq Save and quit
:q! Quit without saving
:/text Search for text
nano Editor
nano is a simple, user-friendly text editor.
It is suitable for beginners because it does not have multiple modes.
Commands are displayed at the bottom of the screen.
Basic Commands
Command Purpose
nano filename Open or create a file
Ctrl + O Save the file
Ctrl + X Exit
Ctrl + K Cut the current line
Ctrl + U Paste the cut text
Ctrl + W Search for text
Steps to Compile and Run a C Program
Step 1: Create the Source File using vi or nano
nano hello.c
or
vi hello.c
Step 2: Write the Program
#include <stdio.h>
int main()
{
printf("Hello Linux\n");
return 0;
}
Save the file as hello.c
In vi : sc → :w → Enter
In nano : Ctrl + O → Enter
Step 3: Compile the Program
gcc hello.c -o hello
gcc – GNU C Compiler
hello.c – Source program
-o – Specifies the name of the output file.
hello – Name of the executable file
If there are no errors, GCC creates an executable file named hello.
Step 4: Run the Program
./hello
./ – Refers to the current directory.
hello – Executable program.
Step 5: Debugging
GDB (GNU Debugger) is a debugging tool used to find and fix errors in C, C++, and other
programs running on Linux.
GDB can
Run a program step by step.
Set breakpoints to pause execution.
View the values of variables.
Find logical and runtime errors.
Continue execution after inspecting the program.
Common GDB Commands
Command Purpose
run Starts the program
break main Sets a breakpoint at main()
next Executes the next line
print x Displays the value of variable x
continue Continues execution
quit Exits GDB