Linux Basics

Package Managers & Software Management

Forget downloading .exe installers from random websites. In Linux, you install, update, and remove software through a package manager — a system that fetches verified software from trusted repositories in a single command.


How Package Management Works

A repository is a collection of pre-compiled, digitally signed software packages hosted on servers maintained by your Linux distribution or trusted third parties. Your system keeps a local database (index) of what's available.

text
Your terminal (apt install git)

Local package index (knows what's available)

Download from Ubuntu/Debian repository servers

Verify signature (prevents tampered packages)

Extract files to correct system locations

Register package in local database

apt — System Package Manager (Ubuntu / Debian / Raspberry Pi OS)

Update the Package Index

Always run this before installing anything. It syncs your local index with the remote repositories. It does not install or upgrade anything yet.

bash
sudo apt update

Install Software

bash
# Install a single package
sudo apt install git

# Install multiple packages at once
sudo apt install git python3 python3-pip cmake ninja-build

# Install without confirmation prompt
sudo apt install -y build-essential gcc g++ make

# Typical embedded development setup in one command
sudo apt install -y \
  git \
  cmake \
  ninja-build \
  python3 \
  python3-pip \
  python3-venv \
  build-essential \
  gcc \
  libusb-1.0-0-dev \
  openocd \
  gdb-multiarch \
  minicom \
  screen

Search for a Package

bash
apt search cmake              # Search by keyword
apt show cmake                # Detailed info about a package
apt list --installed          # List all installed packages
apt list --installed | grep python   # Filter installed packages

Upgrade Software

bash
sudo apt upgrade              # Upgrade all packages to their latest version
sudo apt full-upgrade         # Upgrade with dependency changes (more aggressive)
sudo apt dist-upgrade         # Distribution upgrade — adds/removes packages as needed

Remove Software

bash
sudo apt remove git           # Remove the program (keep config files)
sudo apt purge git            # Remove program AND its config files
sudo apt autoremove           # Remove packages that were installed as dependencies
                              # but are no longer needed
sudo apt clean                # Delete downloaded .deb files from cache
sudo apt autoclean            # Delete only outdated cached .deb files

Adding External Repositories (PPAs)

Sometimes software is not in the official Ubuntu repositories. You can add a PPA (Personal Package Archive) to get it.

bash
# Example: Add a newer version of GCC
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update
sudo apt install gcc-13 g++-13

# Example: Add Node.js repository
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs

# Remove a PPA
sudo add-apt-repository --remove ppa:ubuntu-toolchain-r/test

pip — Python Package Manager

pip installs Python libraries from the PyPI (Python Package Index) at pypi.org.

bash
# Install a package
pip install numpy

# Install a specific version
pip install tensorflow==2.15.0

# Install from a requirements file
pip install -r requirements.txt

# List installed packages
pip list

# Show detailed info about a package
pip show numpy

# Upgrade a package
pip install --upgrade numpy

# Uninstall a package
pip uninstall numpy

# Search (deprecated in newer pip — use pypi.org instead)
pip install esptool            # ESP32 flashing tool
pip install pyserial           # Serial communication
pip install scikit-learn pandas matplotlib

Virtual Environments (Best Practice)

Never install Python packages system-wide with sudo pip install. Always use a virtual environment — it isolates dependencies per project.

bash
# Create a virtual environment in the current directory
python3 -m venv .venv

# Activate it
source .venv/bin/activate       # Linux / macOS
# .venv\Scripts\activate        # Windows PowerShell

# Your prompt changes to show the active env:
# (.venv) rajath@ubuntu:~/projects$

# Install packages inside the env (no sudo needed)
pip install numpy pandas scikit-learn

# Save all installed packages to a file
pip freeze > requirements.txt

# Install from requirements on another machine
pip install -r requirements.txt

# Deactivate when done
deactivate

snap — Universal Packages

Snap packages are self-contained, sandboxed applications that work across all Linux distributions. They auto-update in the background.

bash
# Search for a snap package
snap find code

# Install Visual Studio Code (the professional way on Ubuntu)
sudo snap install code --classic

# Install other tools
sudo snap install arduino                 # Arduino IDE
sudo snap install cmake --classic

# List installed snaps
snap list

# Remove a snap
sudo snap remove code

# Check snap service status
snap services

dpkg — Low-Level Package Tool

apt uses dpkg under the hood. You interact with dpkg directly when installing downloaded .deb files.

bash
# Install a downloaded .deb file
sudo dpkg -i package_name.deb

# Fix broken dependencies after dpkg install
sudo apt install -f

# List all installed packages
dpkg -l

# Check if a specific package is installed
dpkg -l | grep cmake

# Show files installed by a package
dpkg -L cmake

# Show which package owns a file
dpkg -S /usr/bin/gcc

Manual Installation from Source

When a package is not in any repository, you compile it from source code.

bash
# 1. Download source code
git clone https://github.com/someproject/tool.git
cd tool

# 2. Check dependencies (read the README!)
sudo apt install -y libssl-dev libffi-dev

# 3. Configure — generates a Makefile for your system
./configure --prefix=/usr/local

# 4. Build (use -j$(nproc) to use all CPU cores)
make -j$(nproc)

# 5. Install system-wide
sudo make install

# 6. Verify
which tool
tool --version

curl and wget — Downloading Files

Many installation scripts are fetched and run directly from the internet.

bash
# Download a file
wget https://example.com/tool-v1.0.tar.gz

# Download and show progress
wget -c https://example.com/large_file.iso   # -c = resume if interrupted

# Run an install script directly (verify the source first!)
curl -fsSL https://get.docker.com | sudo sh

# Download a file with curl
curl -o filename.tar.gz https://example.com/file.tar.gz

# Fetch a URL and print output to terminal
curl https://api.example.com/status

tar — Extracting Archives

Most downloaded Linux software comes as .tar.gz or .tar.xz archives.

bash
# Extract .tar.gz
tar -xzf archive.tar.gz

# Extract .tar.xz
tar -xJf archive.tar.xz

# Extract to a specific directory
tar -xzf archive.tar.gz -C /opt/

# List archive contents without extracting
tar -tzf archive.tar.gz

# Create an archive
tar -czf my_project.tar.gz ./my_project/

Flag cheatsheet: -c create, -x extract, -z gzip, -J xz, -f file, -v verbose.


Essential Software for Embedded + AI Development

bash
# Core development tools
sudo apt install -y git build-essential gcc g++ make cmake ninja-build pkg-config

# Python ecosystem
sudo apt install -y python3 python3-pip python3-venv python3-dev

# Serial communication and flashing
sudo apt install -y minicom screen picocom
pip install esptool pyserial

# Debugging
sudo apt install -y gdb gdb-multiarch openocd

# USB and device management
sudo apt install -y libusb-1.0-0 libusb-1.0-0-dev usbutils

# Version control
sudo apt install -y git git-lfs

# Compression
sudo apt install -y unzip p7zip-full

# System monitoring
sudo apt install -y htop iotop nethogs

Quick Reference

CommandEffect
sudo apt updateSync package index from repositories
sudo apt install pkgInstall a package
sudo apt install -y pkgInstall without confirmation
sudo apt upgradeUpgrade all packages
sudo apt remove pkgRemove package (keep config)
sudo apt purge pkgRemove package and config
sudo apt autoremoveRemove unused dependencies
apt search keywordSearch for packages
apt show pkgShow package details
pip install libInstall Python library
pip freeze > req.txtSave Python deps
python3 -m venv .venvCreate virtual environment
source .venv/bin/activateActivate virtual environment
sudo dpkg -i file.debInstall a .deb file
sudo snap install pkgInstall snap package
wget URLDownload a file
tar -xzf file.tar.gzExtract a gzip archive
Previous
Permissions & Sudo