Programming on Unix: C, C++, Perl, Python, shell and more
Unix was written by programmers for programmers, and it is still the most comfortable place to write code. This page shows which language suits which job, how to install the tools and where to learn each one for free.
Which language for which job
| Job | Good choices |
|---|---|
| Automating commands, small admin tasks | Shell |
| Larger admin scripts, text and data processing | Python, Perl |
| Websites and web applications | PHP, Python, JavaScript (Node.js), Go |
| System programs, drivers, fast libraries | C, C++, Rust |
| Network services and command-line tools | Go, Rust |
| Large business applications | Java, C# |
| Working with databases | SQL from any of the above |
Install the development tools
# Debian and Ubuntu: compilers, make and headers in one go
sudo apt install build-essential gdb git python3 python3-venv
# RHEL, AlmaLinux, Rocky, Fedora
sudo dnf group install "Development Tools"
sudo dnf install python3 git
# FreeBSD: clang is part of the base system
sudo pkg install gmake gdb git python3
C and C++
Unix itself is written in C, and the C compilers (GCC and Clang) are part of every distribution. A first program:
cat > hello.c <<'EOF'
#include <stdio.h>
int main(void) {
printf("Hello from C\n");
return 0;
}
EOF
gcc -Wall -Wextra -O2 -o hello hello.c
./hello
Always compile with warnings on (-Wall -Wextra), and while developing add -g -fsanitize=address,undefined to catch memory errors. Larger projects use make or CMake to build. Free resources:
- Beej's Guide to C Programming and Beej's Guide to Network Programming
- cppreference.com: reference for C and C++ standard libraries
- LearnCpp.com: a complete, current C++ tutorial
- Linux system call manual pages (section 2)
Python
Python is installed on almost every Linux system and has become the default language for administration scripts, automation (Ansible is written in it) and data work. Use a virtual environment for each project instead of installing packages system-wide:
python3 -m venv ~/venvs/tools
. ~/venvs/tools/bin/activate
pip install requests
Learn it from the official Python tutorial or the free book Automate the Boring Stuff with Python.
Perl
Perl was the Unix administrator's language of choice for decades and is still installed everywhere, so a Perl one-liner often works where nothing else is available. See Perl basics.
Go and Rust
Both compile to a single fast program with no runtime to install, which makes them popular for command-line tools and network services. Many newer Unix tools are written in them: ripgrep, fd and bat in Rust; Docker, Kubernetes and Hugo in Go.
- A Tour of Go and Go by Example
- The Rust Programming Language (the official book, free online) and Rust by Example
Version control
Whatever language you use, keep your code (and your configuration files) in Git:
git init
git add .
git commit -m "first version"
Pro Git is the free, complete guide.
Web programming
For how programs talk to web servers, start with CGI, the original mechanism, then PHP and setting up a LAMP server.