Skip to main content

System Requirements

Before building Minishell, ensure your system has the following prerequisites:

C Compiler

GCC or compatible C compiler with C99 support

GNU Make

Build automation tool (version 3.81 or higher)

Readline Library

GNU Readline for command-line editing and history

Standard Libraries

POSIX-compliant system (Linux, macOS, BSD)

Install Dependencies

sudo apt-get update
sudo apt-get install build-essential libreadline-dev

Building from Source

1

Clone or Download the Source Code

Navigate to your preferred directory and obtain the Minishell source code:
cd ~/projects
# If you have the source code in a directory
cd minishell
Verify you have all source files:
ls *.c *.h Makefile
You should see files like main.c, minishell.h, and Makefile.
2

Compile the Project

Minishell uses a Makefile for compilation. The build configuration includes:
CC        = cc
CFLAGS    = -Wall -Wextra -Werror -g
READLINE  = -lreadline
NAME      = minishell
Build the executable:
make
This compiles all source files and links them with the readline library. The compilation flags ensure:
  • -Wall -Wextra -Werror: Enable all warnings and treat them as errors
  • -g: Include debug symbols for debugging with GDB
  • -lreadline: Link against the GNU Readline library
The first build may take 10-30 seconds depending on your system. Subsequent builds are faster due to incremental compilation.
3

Verify the Build

After successful compilation, you should see the minishell executable:
ls -lh minishell
Expected output:
-rwxr-xr-x 1 user user 45K Mar 7 12:00 minishell
Check that the executable is properly linked:
file minishell
Expected output:
minishell: ELF 64-bit LSB executable, x86-64, dynamically linked
4

Test the Installation

Run Minishell to verify it works:
./minishell
You should see the Minishell prompt. Try a simple command:
minishell> echo "Hello, World!"
Hello, World!
minishell> exit
The shell displays a custom prompt that includes your username and current directory, similar to bash.

Makefile Commands

The Minishell Makefile provides several useful targets:
# Compile the project (default target)
make
# or explicitly
make all

Makefile Structure

The Makefile compiles these source files:
CFILES = main.c split.c utils.c utils2.c builtins.c builtins_utils.c exit.c\
         parse_imput.c ft_count_pipes.c ft_prepare_nodes.c\
         ft_execute_commands.c set_full_cmd_path.c set_infile_outfile.c\
         init_shell.c set_bin_path.c env_parsed.c split_utils.c\
         env_parsed2.c utils3.c ft_execute_one_command.c signals.c\
         more_parsing.c ft_print_prompt.c
Each .c file is compiled to a .o object file, then all objects are linked together:
$(NAME) : $(OFILES)
    $(CC) $(CFLAGS) $(OFILES) -o $(NAME) $(READLINE)

Troubleshooting

Problem: The readline development headers are not installed.Solution: Install the readline development package:
Ubuntu/Debian
sudo apt-get install libreadline-dev
macOS
brew install readline
# If installed but not found, add to CFLAGS:
export CFLAGS="-I/usr/local/opt/readline/include"
export LDFLAGS="-L/usr/local/opt/readline/lib"
make re
Problem: The linker cannot find the readline library.Solution: Ensure the library is installed and properly linked:
# Check if libreadline is installed
ldconfig -p | grep readline

# On macOS, set library path
export LDFLAGS="-L/usr/local/opt/readline/lib"
make re
Problem: Code doesn’t compile with strict flags (-Wall -Wextra -Werror).Solution: The codebase should compile without warnings. If you encounter errors:
  1. Ensure you’re using a C99-compatible compiler:
    gcc --version
    
  2. Clean and rebuild:
    make fclean
    make
    
  3. If issues persist, check that all source files are present and unmodified.
Problem: Runtime error on startup.Solution: Debug with GDB:
# Rebuild with debug symbols (already included by default)
make re

# Run with GDB
gdb ./minishell
(gdb) run
# If it crashes:
(gdb) backtrace
Common causes:
  • Invalid environment variables
  • Memory allocation failures
  • Missing terminal capabilities for readline
Problem: GNU Make is not installed.Solution: Install the build tools:
Ubuntu/Debian
sudo apt-get install build-essential
macOS
xcode-select --install

Optional: Install System-Wide

To make Minishell accessible from anywhere on your system:
# Option 1: Copy to a directory in your PATH
sudo cp minishell /usr/local/bin/

# Option 2: Create a symbolic link
sudo ln -s $(pwd)/minishell /usr/local/bin/minishell

# Verify installation
which minishell
minishell --version  # If version flag is implemented
Installing system-wide is optional. For development and testing, running ./minishell from the build directory is recommended.

Next Steps

Now that Minishell is installed, proceed to the Quick Start guide to learn how to use it:

Quick Start Guide

Learn the basics of using Minishell with practical examples

Build docs developers (and LLMs) love