Keeping your Kali Linux system up-to-date is crucial for security, stability, and access to the latest tools. Instead of manually running apt update and apt upgrade every time, why not automate the process with a shell script?
In this guide, I’ll walk you through a powerful yet simple shell script that:
✅ Checks system info (OS version, kernel, disk, and memory)
✅ Backs up installed packages before updating
✅ Updates and upgrades all packages safely
✅ Cleans up unnecessary files
✅ Checks if a reboot is required
📜 The Kali Linux Update Script
#!/bin/bash
# Kali Linux Update Script
# Displays system info and performs updates
# Color settings
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Root check
if [ "$(id -u)" -ne 0 ]; then
echo -e "${RED}Error: This script must be run as root${NC}"
exit 1
fi
# Display system info
echo -e "${YELLOW}=== 🖥️ System Information ===${NC}"
echo -e "${GREEN}Kali Linux Version:${NC}"
cat /etc/os-release | grep PRETTY_NAME
echo -e "${GREEN}Kernel Version:${NC}"
uname -r
echo -e "${GREEN}System Architecture:${NC}"
uname -m
echo -e "${GREEN}Disk Usage:${NC}"
df -h /
echo -e "${GREEN}Memory Usage:${NC}"
free -h
# Backup installed packages
echo -e "${YELLOW}\n=== 📦 Backing up package list ===${NC}"
backup_dir="/var/backups/$(date +%Y%m%d)"
mkdir -p "$backup_dir"
dpkg --get-selections > "$backup_dir/dpkg_selections_$(date +%Y%m%d-%H%M%S).list"
echo -e "Backup saved to: ${GREEN}$backup_dir${NC}"
# Update package lists
echo -e "${YELLOW}\n=== 🔄 Updating package lists ===${NC}"
apt update
# Show upgradable packages
echo -e "${YELLOW}\n=== ⬆️ Packages available for upgrade ===${NC}"
apt list --upgradable
# Ask before upgrading
read -p "Do you want to proceed with the upgrade? [y/N] " choice
case "$choice" in
y|Y )
echo -e "${YELLOW}\n=== 🚀 Upgrading packages ===${NC}"
apt full-upgrade -y
echo -e "${YELLOW}\n=== 🗑️ Cleaning up old packages ===${NC}"
apt autoremove -y
apt clean
;;
* )
echo -e "${RED}Upgrade cancelled${NC}"
;;
esac
# Post-update status
echo -e "${YELLOW}\n=== ✅ Update completed ===${NC}"
echo -e "${GREEN}Final Kernel Version:${NC}"
uname -r
echo -e "${GREEN}Final Disk Usage:${NC}"
df -h /
echo -e "${GREEN}Final Memory Usage:${NC}"
free -h
# Reboot check
if [ -f /var/run/reboot-required ]; then
echo -e "${RED}\n⚠️ Warning: System reboot required!${NC}"
cat /var/run/reboot-required.pkgs
fi
exit 0
🛠️ How to Use the Script
💾 Save the script
Copy the code above and save it asupdate_kali.sh.🔒 Make it executable
chmod +x update_kali.sh⚡ Run it as root
sudo ./update_kali.sh
🔍 Key Features Explained
1. 🖥️ System Information Check
Before making any changes, the script displays:
- 📌 Kali Linux version (from
/etc/os-release) - ⚙️ Kernel version (
uname -r) - 💾 Disk & memory usage (
df -h,free -h)
This helps you monitor system health before and after updates.
2. 📦 Safe Package Backup
The script creates a backup of your installed packages in /var/backups/. If something breaks, you can restore packages using:
dpkg --set-selections < backup_file.list
apt-get dselect-upgrade
3. 🚀 Controlled Updates & Upgrades
- First, it runs
apt updateto refresh package lists. - Then, it shows upgradable packages before asking for confirmation.
- If approved, it runs
apt full-upgrade -y(safer thandist-upgrade).
4. 🗑️ Automatic Cleanup
After upgrading, it removes old dependencies (apt autoremove) and clears the package cache (apt clean).
5. ⚠️ Reboot Check
If a reboot is needed (common after kernel updates), the script warns you explicitly.
💡 Why Use This Script?
🔹 ⏳ Saves time – No more typing multiple commands.
🔹 🛡️ Reduces risk – Backs up packages before making changes.
🔹 🔍 Transparent – Shows what’s being upgraded.
🔹 ⚙️ Flexible – Asks for confirmation before upgrading.
🎯 Final Thoughts
This script is perfect for security researchers, penetration testers, and Kali Linux enthusiasts who want to keep their systems secure without manual hassle.
Try it out and let me know in the comments if you’d like any improvements!